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

    class N
    {
    int K;
    void display()
    {
    System.out.println(K);
    }
    }
    class M extends N
    {
    int L;
    void display()
    {
    System.out.println(L);
    }
    }
    public class inheritance_Example
    {
    public static void main(String args[])
    {
    M object = new M();
    object.K=5;
    object.L=6;
    object.display();
    }
    }
    1. 2
    2. 3
    3. 4
    4. 5
    5. 6
Correct Option: E

Class N & class M both contain display() method, class M inherits class N, when display() method is called by object of class M, display() method of class M is executed rather than that of Class N.



Your comments will be displayed only after manual approval.