Java Inheritance and Abstraction

Last Updated :
Discuss
Comments

Question 1

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


  • A

    Every Java class extends Object class either directly or indirectly.

  • B

    Only classes without a superclass extend Object class.

  • C

    The Object class cannot be extended.


  • D

    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();
    }
}


  • A

    Class A

  • B

    Class B

  • C

    Compilation error

  • D

    Runtime error

Question 3

Which keyword is used to create a subclass in Java?

  • A

    implements

  • B

    inherits

  • C

    extends

  • D

    interface

Question 4

What is abstraction in Java?

  • A

    Hiding method names

  • B

    Hiding internal implementation and showing only functionality

  • C

    Creating private variables

  • D

    Inheriting classes

Question 5

Which keyword is used to define an abstract class?


  • A

    interface

  • B

    abstract


  • C

    static

  • D

    private


Question 6

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

  • A

    It will not compile.

  • B

    The class can still be abstract.

  • C

    Java will automatically provide an abstract method.

  • D

    It becomes a concrete class.

Question 7

Which of the following statements about inheritance is false?


  • A

    Java supports single inheritance.

  • B

    Java allows multiple class inheritance using extends.

  • C

    Interfaces can be used to achieve multiple inheritance.


  • D

    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