Java Inheritance and Abstraction

Last Updated :
Discuss
Comments

Question 1

Which of the following statements about the Object class in Java is true?


  • Every Java class extends Object class either directly or indirectly.

  • Only classes without a superclass extend Object class.

  • The Object class cannot be extended.


  • Object class is an abstract class.


Question 2

What will be the output of the following code?

Java
class A {
    void display() {
        System.out.println("Class A");
    }
}
class B extends A {
    void display() {
        System.out.println("Class B");
    }
}
public class Main {
    public static void main(String[] args) {
        A obj = new B();
        obj.display();
    }
}


  • Class A

  • Class B

  • Compilation error

  • Runtime error

Question 3

Which keyword is used to create a subclass in Java?

  • implements

  • inherits

  • extends

  • interface

Question 4

What is abstraction in Java?

  • Hiding method names

  • Hiding internal implementation and showing only functionality


  • Creating private variables

  • Inheriting classes


Question 5

Which keyword is used to define an abstract class?


  • interface

  • abstract


  • static

  • private


Question 6

What happens if an abstract class does not have any abstract methods?

  • It will not compile.

  • The class can still be abstract.

  • Java will automatically provide an abstract method.

  • It becomes a concrete class.

Question 7

Which of the following statements about inheritance is false?


  • Java supports single inheritance.

  • Java allows multiple class inheritance using extends.

  • Interfaces can be used to achieve multiple inheritance.


  • The super keyword can be used to invoke the parent class constructor.


There are 7 questions to complete.

Take a part in the ongoing discussion