Java | Abstract Class and Interface | Question 3

Predict the output of the following program.

filter_none

edit
close

play_arrow

link
brightness_4
code

abstract class demo
{
    public int a;
    demo()
    {
        a = 10;
    }
  
    abstract public void set();
      
    abstract final public void get();
  
}
  
class Test extends demo
{
  
    public void set(int a)
    {
        this.a = a;
    }
  
    final public void get()
    {
        System.out.println("a = " + a);
    }
  
    public static void main(String[] args)
    {
        Test obj = new Test();
        obj.set(20);
        obj.get();
    }
}
  

chevron_right


(A) a = 10
(B) a = 20
(C) Compilation error


Answer: (C)

Explanation: Final method can’t be overridden. Thus, an abstract function can’t be final.

Quiz of this Question



My Personal Notes arrow_drop_up