Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following Java program?
class X
{
int a;
double b;
}
class Y extends X
{
int c;
}
class Output
{
public static void main(String args[])
{
X a = new X();
Y b = new Y();
Class obj;
obj = b.getClass();
System.out.print(obj.isInstance(a));
}
}

What will be the output of the following Java program?
class X
{
int a;
double b;
}
class Y extends X
{
int c;
}
class Output
{
public static void main(String args[])
{
X a = new X();
Y b = new Y();
Class obj;
obj = b.getClass();
System.out.print(obj.isInstance(a));
}
}
a) 0
b) 1
c) true
d) false

Answer: d
Explanation: Although class Y extends class X but still a is not considered related to Y. hence isInstance() returns false.

Join The Discussion