Object & Classes
- 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.isInstance(p));
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Although class M extends class N but still a is not considered related to M. hence isInstance() returns false.
- 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(q.equals(p));
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
false
- 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());
}
}
-
View Hint View Answer Discuss in Forum
NA
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.
- Which of these Exceptions is thrown by loadClass() method of ClassLoader class?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
ClassNotFoundException
- Which of these methods returns the total number of bytes of memory available to the program?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
TotalMemory() returns the total number of bytes available to the program.