โ† All 1Z0-811 Flashcard Decks

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
  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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().

  6. 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.

  7. 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.