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

    class N
    {
    public int K;
    public int L;
    N()
    {
    K = 5;
    L = 2;
    }
    }
    class M extends N
    {
    int p;
    M()
    {
    super();
    }
    }
    public class inheritance_super_use
    {
    public static void main(String args[])
    {
    M obj = new M();
    System.out.println(obj.K + " " + obj.L);
    }
    }
    1. 5 1
    2. 1 5
    3. 5 2
    4. 2 5
    5. None of these
Correct Option: C

Keyword super is used to call constructor of class N by constructor of class M. Constructor of a initializes K & L to 5 & 2 respectively.



Your comments will be displayed only after manual approval.