carolyn206
carolyn206 13h ago • 0 views

Multiple Choice Questions on Java Inheritance (Superclass and Subclass)

Hey everyone! 👋 Getting ready to conquer Java inheritance or just need a quick refresh on superclass and subclass concepts? 🤔 I've got a fantastic set of multiple-choice questions that'll help you solidify your understanding. Let's dive in and master these core OOP principles!
💻 Computer Science & Technology
🪄

🚀 Can't Find Your Exact Topic?

Let our AI Worksheet Generator create custom study notes, online quizzes, and printable PDFs in seconds. 100% Free!

✨ Generate Custom Content

1 Answers

✅ Best Answer
User Avatar
philip652 Mar 16, 2026

📚 Quick Study Guide

  • 🔗 Inheritance Basics: Allows a class (subclass/child) to inherit fields and methods from another class (superclass/parent). This promotes code reusability.
  • ➡️ The `extends` Keyword: Used to establish an inheritance relationship. A subclass `extends` a superclass, gaining access to its non-private members.
  • ⬆️ The `super` Keyword: Used to refer to the immediate superclass object. It can call superclass constructors (`super()`) or access superclass methods/fields (`super.method()`, `super.field`).
  • 🔄 Method Overriding: A subclass provides a specific implementation for a method that is already defined in its superclass. The method signature (name, parameters, return type) must be the same.
  • 🏗️ Constructors in Inheritance: Superclass constructors are invoked from the subclass constructor, either implicitly (default no-arg `super()`) or explicitly using `super(...)`. This ensures proper initialization of the superclass portion of the object.
  • 🔒 Access Modifiers & Inheritance: `private` members of a superclass are not directly inherited by the subclass. `protected` members are accessible within the same package and by subclasses in any package.
  • 🛑 The `final` Keyword: If a class is declared `final`, it cannot be subclassed. If a method is `final`, it cannot be overridden. If a variable is `final`, its value cannot be changed once assigned.

📝 Practice Quiz

  1. What is the primary purpose of inheritance in Java?
    A) To allow multiple inheritance of classes
    B) To achieve runtime polymorphism
    C) To promote code reusability and establish an 'is-a' relationship
    D) To hide implementation details from the user
  2. Which keyword is used to explicitly call a constructor of the superclass from the subclass constructor?
    A) `this`
    B) `new`
    C) `super`
    D) `extends`
  3. If a method in a subclass has the same name, parameters, and return type as a method in its superclass, what concept is being applied?
    A) Method overloading
    B) Method hiding
    C) Method overriding
    D) Method shadowing
  4. Which of the following statements about the `final` keyword in Java inheritance is TRUE?
    A) A `final` class can be extended by a subclass.
    B) A `final` method can be overridden in a subclass.
    C) A `final` variable can be reassigned after its initial declaration.
    D) A `final` class cannot be extended, and a `final` method cannot be overridden.
  5. Consider the following code:
    class Animal {
    void eat() { System.out.println("Animal eats"); }
    }

    class Dog extends Animal {
    void eat() { System.out.println("Dog eats bones"); }
    }

    public class Test {
    public static void main(String[] args) {
    Animal myPet = new Dog();
    myPet.eat();
    }
    }
    What will be the output?
    A) "Animal eats"
    B) "Dog eats bones"
    C) Compile-time error
    D) Runtime error
  6. Which access modifier, when applied to a superclass member, makes it accessible within the same package and to subclasses in any package?
    A) `private`
    B) `default` (package-private)
    C) `protected`
    D) `public`
  7. If a superclass has a constructor that takes arguments, and the subclass does not explicitly call a superclass constructor using `super()`, what happens?
    A) The superclass's no-argument constructor is automatically called.
    B) A compile-time error occurs because the superclass's constructor must be explicitly called.
    C) The subclass constructor automatically calls the superclass's argument-based constructor.
    D) The program will run, but the superclass will not be initialized.
Click to see Answers

1. C
2. C
3. C
4. D
5. B
6. C
7. B

Join the discussion

Please log in to post your answer.

Log In

Earn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! 🚀