Java | Abstract Class and Interface | Question 3

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



My Personal Notes arrow_drop_up

Recommended Posts:



3 Average Difficulty : 3/5.0
Based on 1 vote(s)






User Actions