Home » JAVA Programming » Object & Classes » Question
  1. What is the output of this program?
    class N
    {
    int p;
    double q;
    }
    class M extends N
    {
    int r;
    }
    public class Result
    {
    public static void main(String args[])
    {
    N p = new N();
    M q = new M();
    Class object;
    object = q.getClass();
    System.out.print(object.getSuperclass());
    }
    }
    1. N
    2. M
    3. Class N
    4. Class M
    5. None of these
Correct Option: C

getSuperClass() returns the super class of an object. q is an object of class M which extends class N , Hence Super class of q is N. therefore class N is printed.



Your comments will be displayed only after manual approval.