Java Chapter 6 Flashcards
(312 cards)
What types of members does a subclass inherit from its parent class in Java?
A subclass inherits all public and protected methods/variables, as well as package-private (default) members only if they are in the same package. It never inherits private members.
True or False: A subclass inherits private members from its parent class.
False. Private members remain hidden in the parent and are not accessible to the subclass.
Explain the transitivity of inheritance in Java using the following code:
The Rhinoceros class inherits from Mammal, which in turn inherits from Animal. Thus, Rhinoceros indirectly inherits from Animal, demonstrating transitivity.
Given the hierarchy Rhinoceros → Mammal → Animal, is a Rhinoceros object also an instance of Animal? Why?
Yes, due to inheritance transitivity. Since Rhinoceros extends Mammal, and Mammal extends Animal, a Rhinoceros is also an Animal.
In Java, under what condition can a subclass inherit package-private (default) members from its parent?
Only if the subclass and parent are in the same package. Otherwise, package-private members are not inherited.
Which keyword in Java explicitly prevents a member from being inherited by subclasses?
The private keyword. Subclasses cannot inherit private members.
What types of members does a subclass inherit from its parent class in Java?
A subclass inherits all public and protected methods/variables, as well as package-private (default) members only if they are in the same package. It never inherits private members.
True or False: A subclass inherits private members from its parent class.
False. Private members remain hidden in the parent and are not accessible to the subclass.
Explain the transitivity of inheritance in Java using the following code:
The Rhinoceros class inherits from Mammal, which in turn inherits from Animal. Thus, Rhinoceros indirectly inherits from Animal, demonstrating transitivity.
Given the hierarchy Rhinoceros → Mammal → Animal, is a Rhinoceros object also an instance of Animal? Why?
Yes, due to inheritance transitivity. Since Rhinoceros extends Mammal, and Mammal extends Animal, a Rhinoceros is also an Animal.
In Java, under what condition can a subclass inherit package-private (default) members from its parent?
Only if the subclass and parent are in the same package. Otherwise, package-private members are not inherited.
Which keyword in Java explicitly prevents a member from being inherited by subclasses?
The private keyword. Subclasses cannot inherit private members.
What types of members does a subclass inherit from its parent class in Java?
A subclass inherits all public and protected methods/variables, as well as package-private (default) members only if they are in the same package. It never inherits private members.
True or False: A subclass inherits private members from its parent class.
False. Private members remain hidden in the parent and are not accessible to the subclass.
Explain the transitivity of inheritance in Java using the following code:
The Rhinoceros class inherits from Mammal, which in turn inherits from Animal. Thus, Rhinoceros indirectly inherits from Animal, demonstrating transitivity.
Given the hierarchy Rhinoceros → Mammal → Animal, is a Rhinoceros object also an instance of Animal? Why?
Yes, due to inheritance transitivity. Since Rhinoceros extends Mammal, and Mammal extends Animal, a Rhinoceros is also an Animal.
In Java, under what condition can a subclass inherit package-private (default) members from its parent?
Only if the subclass and parent are in the same package. Otherwise, package-private members are not inherited.
Which keyword in Java explicitly prevents a member from being inherited by subclasses?
The private keyword. Subclasses cannot inherit private members.
What types of members does a subclass inherit from its parent class in Java?
A subclass inherits all public and protected methods/variables, as well as package-private (default) members only if they are in the same package. It never inherits private members.
True or False: A subclass inherits private members from its parent class.
False. Private members remain hidden in the parent and are not accessible to the subclass.
Explain the transitivity of inheritance in Java using the following code:
The Rhinoceros class inherits from Mammal, which in turn inherits from Animal. Thus, Rhinoceros indirectly inherits from Animal, demonstrating transitivity.
Given the hierarchy Rhinoceros → Mammal → Animal, is a Rhinoceros object also an instance of Animal? Why?
Yes, due to inheritance transitivity. Since Rhinoceros extends Mammal, and Mammal extends Animal, a Rhinoceros is also an Animal.
In Java, under what condition can a subclass inherit package-private (default) members from its parent?
Only if the subclass and parent are in the same package. Otherwise, package-private members are not inherited.
Which keyword in Java explicitly prevents a member from being inherited by subclasses?
The private keyword. Subclasses cannot inherit private members.