Open In App

Java | Abstract Class and Interface | Question 3

Like Article
Like
Save
Share
Report

Predict the output of the following program.




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


(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


Last Updated : 28 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Similar Reads