Skip to content
Related Articles

Related Articles

Java | Abstract Class and Interface | Question 3
  • Difficulty Level : Medium
  • Last Updated : 11 Jan, 2016

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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :