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 Output
    {
    public static void main(String args[])
    {
    N p = new N();
    M q = new M();
    Class object;
    object = p.getClass();
    System.out.print(object.getName());
    }
    }
    1. p
    2. q
    3. N
    4. M
    5. r
Correct Option: C

getClass() is used to obtain the class of an object, here ‘p’ is an object of class ‘N’. hence a.getClass() returns ‘N’ which is stored in class Class object object.



Your comments will be displayed only after manual approval.