-
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());
}
}
-
- p
- q
- N
- M
- 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.