567). Which of these classes encapsulate runtime state of an object?
[A]Class
[B]System
[C]Runtime
[D]Cache
Show Answer
Correct Answer: Class
Notes:
Answer: a
Explanation: None.
568). Which of these methods returns the class of an object?
[A] getClass()
[B]Class()
[C]WhoseClass()
[D]WhoseObject()
Show Answer
Correct Answer: getClass()
Notes:
Answer: a
Explanation: None.
569). Which of these methods return a class object given its name?
[A]getClass()
[B]findClass()
[C]getSystemClass()
[D] findSystemClass()
Show Answer
Correct Answer: findSystemClass()
Notes:
Answer: d
Explanation: findSystemClass() returns a class object given its name.
570). Which of these class defines how the classes are loaded?
[A]Class
[B]System
[C]Runtime
[D]ClassLoader
Show Answer
Correct Answer: ClassLoader
Notes:
Answer: d
Explanation: None.
571). 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 = a.getClass();
System.out.print(obj.getName());
}
}
Show Answer
Correct Answer: X
Notes:
Answer: a
Explanation: getClass() is used to obtain the class of an object, here ‘a’ is an object of class ‘X’. hence a.getClass() returns ‘X’ which is stored in class Class object obj.
Output:$ javac Output.java
$ java Output
X
572). 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.getSuperclass());
}
}
[A]X
[B]Y
[C] class X
[D] class Y
Show Answer
Correct Answer: class X
Notes:
Answer: c
Explanation: getSuperClass() returns the super class of an object. b is an object of class Y which extends class X, Hence Super class of b is X. therefore class X is printed.
Output:
$ javac Output.java
$ java Output
class X
573). 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.isLocalClass());
}
}
[A]0
[B]1
[C]true
[D]false
Show Answer
Correct Answer: false
Notes:
Answer: d
Explanation: None.
Output:
$ javac Output.java
$ java Output
false