Home » JAVA Programming » Inheritance » Question
  1. What is the output of this program?

    final class n
    {
    int K;
    }
    class n1 extends n
    {
    int L;
    System.out.println(L + " " + K);
    }
    public class inheritance_Example
    {
    public static void main(String args[])
    {
    n1 obj = new n1();
    obj.display();
    }
    }
    1. Runtime Error
    2. 4 4
    3. Compilation Error
    4. 5 5
    5. None of these
Correct Option: C

class n has been declared final hence it cannot be inherited by any other class. Hence class B does not have member i, giving compilation error.

Output: Compilation Error



Your comments will be displayed only after manual approval.