AllInfoHub Logo

AllInfoHub – MCQ Practice

Inheritance and Polymorphism – Multiple Choice Questions (MCQs)

  1. 1. What is inheritance in Java?

    • A. The ability of an object to take on many forms
    • B. The mechanism of deriving a new class from an existing one
    • C. The process of hiding the implementation details of an object
    • D. The way objects interact with each other
  2. 2. Which keyword is used to implement inheritance in Java?

    • A. inherits
    • B. extends
    • C. implements
    • D. subclass
  3. 3. What is a superclass (or parent class) in Java?

    • A. The class that is created first
    • B. The class from which another class inherits
    • C. A class with no methods
    • D. The main class in a program
  4. 4. What is a subclass (or child class) in Java?

    • A. The class that inherits from another class
    • B. A class that cannot have instances
    • C. A class with only static methods
    • D. The class that is created last
  5. 5. Can a class inherit from multiple classes directly in Java?

    • A. Yes
    • B. No
    • C. Only interfaces
    • D. Only abstract classes
  6. 6. What is the output of the following code? `class Animal { void makeSound() { System.out.println(\Generic sound\"); } } class Dog extends Animal { void makeSound() { System.out.println(\""Woof\""); } public static void main(String[] args) { Dog myDog = new Dog(); myDog.makeSound(); } }`"""

    • A. Generic sound
    • B. Woof
    • C. Error
    • D. None
  7. 7. What is method overriding in Java?

    • A. Defining a new method in a subclass with the same name and signature as a method in its superclass
    • B. Calling a method from the superclass
    • C. Combining methods from different classes
    • D. Deleting a method from a superclass
  8. 8. How do you call a method of the superclass from within a subclass method that has overridden it?

    • A. Using `this.superclassMethod()`
    • B. Using `super.superclassMethod()`
    • C. Using `ParentClass.superclassMethod(this)`
    • D. Using `self.superclassMethod()`
  9. 9. What is the output of the following code? `class Parent { void greet() { System.out.println(\Hello from Parent\"); } } class Child extends Parent { void greet() { super.greet(); System.out.println(\""Hello from Child\""); } public static void main(String[] args) { Child myChild = new Child(); myChild.greet(); } }`"""

    • A. Hello from Child
    • B. Hello from Parent\nHello from Child
    • C. Hello from Parent
    • D. Error
  10. 10. What is polymorphism in Java?

    • A. The ability of an object to take on many forms
    • B. The mechanism of deriving a new class from an existing one
    • C. The bundling of data and methods
    • D. The way objects interact with each other
  11. 11. Which of the following is NOT a way to achieve polymorphism in Java?

    • A. Method overloading
    • B. Method overriding
    • C. Using interfaces
    • D. Class inheritance
  12. 12. What is compile-time polymorphism (static binding) in Java?

    • A. Polymorphism achieved through method overriding
    • B. Polymorphism achieved through method overloading
    • C. Polymorphism achieved through inheritance
    • D. Polymorphism achieved through interfaces