Abstraction


  1. What is the output of this program?

    class N
    {
    public int K;
    protected int L;
    }
    class M extends N
    {
    int L;
    void display()
    {
    super.L = 5;
    System.out.println(K + " " + L);
    }
    }
    public class Result
    {
    public static void main(String args[])
    {
    M object = new M();
    object.K=3;
    object.L=4;
    object.display();
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Both class N & M have member with same name that is L, member of class M will be called by default if no specifier is used. K contains 3 & L contains 4, printing 3 4.


  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 MethodOverriding
    {
    public static void main(String args[])
    {
    M object = new M();
    object.K=6;
    object.L=5;
    object.display();
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    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.



  1. What is the output of this program?

    class N
    {
    public int K;
    public int L;
    N()
    {
    K = 5;
    L = 6;
    }
    }
    class M extends N
    {
    int p;
    M()
    {
    super();
    }
    }
    public class super_Example
    {
    public static void main(String args[])
    {
    M object = new M();
    System.out.println(object.K + " " + object.L);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

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


  1. What is the output of this program?

    class N
    {
    public int K;
    private int L;
    }
    class M extends N
    {
    void display()
    {
    super.K = super.L + 2;
    System.out.println(super.K + " " + super.L);
    }
    }
    public class inheritance_Example
    {
    public static void main(String args[])
    {
    M object = new M();
    object.K=1;
    object.L=2;
    object.display();
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Class contains a private member variable L, this cannot be inherited by subclass M and does not have access to it.



  1. Which of these packages contains abstract keyword?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    java.lang