What will be the output of the following Java program?

abstract class A 
       int i;
       abstract void display();
   class B extends A 
       int j;
       void display() 
   class Abstract_demo 
       public static void main(String args[])
           B obj = new B();

a) 0
b) 2
c) Runtime Error
d) Compilation Error

1 thought on “What will be the output of the following Java program?”

  1. b
    Explanation: class A is an abstract class, it contains a abstract function display(), the full implementation of display() method is given in its subclass B, Both the display functions are the same. Prototype of display() is defined in class A and its implementation is given in class B.
    $ javac Abstract_demo.java
    $ java Abstract_demo

Leave a Comment