Discussion
What will be the output of the program?
public class Probe34
{
static void show()
{
Object o = new Object();
String text = o.toString();
System.out.println(text.startsWith("java.lang.Object@"));
}
public static void main(String[] args)
{
show();
}
}
Answer: B
Object's default toString is the class name, an at sign, and the hash code in hexadecimal, so the text does begin with java.lang.Object@ and the test is true. The digits after it vary between runs, which is why the question asks about the prefix rather than the whole string.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development