Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Which two statements are true about or classes?

Answer» Statement (4) describes an example of the equals() method behaving transitively. By the way, x, y,and z will all be the same type of wrapper. Statement (5) is true because x and y are referring to the same String object. Statement (1) is incorrect—the fragment will compile. Statement (2) is incorrect because x == y means that the two reference variables are referring to the same object. Statement (3) will only be true if x and y refer to the same String. It is possible for x and y to refer to two different String objects with the same value.
2.

What will be the output of the program? How many String objects have been created?

Answer» Line 1 creates two, one referred to by x and the lost String "xyz". Line 2 creates one (for a total of three). Line 3 creates one more (for a total of four), the concatenated String referred to by x with a value of "xyzabc".
3.

What two statements are true about the result obtained from calling ?

Answer» (2) and (3) are correct. The result range for random() is 0.0 to < 1.0; 1.0 is not in range.
4.

Select how you would start the program to cause it to print:

Answer» Arguments start at array element 0 so the fourth arguement must be 2 to produce the correct output.