Sail E0 Webinar
Question


What is the output of this program?


class A {
int i;
int j;
A() {
i = 1;
j = 2;
}
}
class Output {
public static void main(String args[])
{
A obj1 = new A();
System.out.print(obj1.toString());
}
}
Options:
A .  true
B .  false
C .  String associated with obj1
D .  Compilation Error
Answer: Option C

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.

output:
$ javac Output.java
$ java Output
A@1cd2e5f



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers