Inheritance and Polymorphism Flashcards
7 cards from real 1Z0-811 practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Inheritance and Polymorphism flashcards as text
Which keyword is used in Java to create a subclass that inherits from a parent class?
Answer: extends
The 'extends' keyword is used to create a subclass that inherits fields and methods from a parent class.
How many classes can a Java class directly extend?
Answer: Only one
Java supports single inheritance for classes, meaning a class can only directly extend one other class.
What does calling 'super()' inside a constructor do?
Answer: Calls the parent class constructor
When 'super()' is used in a constructor, it calls the parent class's constructor to initialize inherited fields.
Which access modifier makes a member accessible to subclasses in different packages but not to unrelated classes?
Answer: protected
The 'protected' access modifier allows access from subclasses regardless of package and from classes within the same package.
Are constructors inherited by subclasses in Java?
Answer: No, constructors are not inherited
Constructors are not inherited in Java; however, subclasses can call parent constructors using super().
What is the implicit parent class of every Java class that does not explicitly extend another class?
Answer: java.lang.Object
Every Java class implicitly extends java.lang.Object if no other parent class is specified.
Given: class Animal {} and class Dog extends Animal {}, which statement is true?
Answer: Dog is a type of Animal
In an 'is-a' relationship, Dog is a type of Animal because Dog extends Animal, inheriting its behavior.