Object & Classes
- What is the output of this program?
public class Result
{
public static void main(String args[])
{
Object o = new Object();
System.out.print(o.getClass());
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
class java.lang.Object
- Which of these methods returns the class of an object?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
getClass()
- Which of these classes encapsulate runtime state of an object?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Class
- What is the output of this program?
class N
{
int K;
int L;
N()
{
K = 1;
L = 2;
}
}
public class Result
{
public static void main(String args[])
{
N object = new N();
System.out.print(object.toString());
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
toString() is method of class Object, since it is superclass of every class, every object has this method. toString() returns the string associated with the calling object.
- What is the output of this program?
public class Result
{
public static void main(String args[])
{
Object object = new Object();
System.out.print(object.getclass());
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Result.java:6: error: cannot find symbol
System.out.print(object.getclass());
^
symbol: method getclass()
location: variable object of type Object
1 error
output: Compilation error