Java - Java.lang Class Questions and Answers
Practice ModeShowing 10 of 24 questions
Q1
What is the value of "d" after this line of code has been executed?
double d = Math.round ( 2.5 + Math.random( ));
Answer: Option B
Q2
Which of the following would compile without error?
Answer: Option A
Q3
Which of the following are valid calls to
Math.max?
Math.max(1,4)
Math.max(2.3, 5)
Math.max(1, 3, 5, 7)
Math.max(-1.5, -2.8f)
Answer: Option A
Q4
public class Myfile
{
public static void main (String[] args)
{
String biz = args[1];
String baz = args[2];
String rip = args[3];
System.out.println("Arg is " + rip);
}
}
Select how you would start the program to cause it to print: Arg is 2
Answer: Option C
Q5
Which of the following is the root class for all Java classes?
Answer: Option A
Explanation: Object class is the root of the class hierarchy in Java
Q6
What method is used to get the string representation of an object?
Answer: Option A
Explanation: toString() method returns string representation of object
Q7
Which method is called when an object is created?
Answer: Option A
Explanation: Constructor is called when object is instantiated
Q8
What is the return type of the hashCode() method?
Answer: Option A
Explanation: hashCode() returns an integer value
Q9
Which class provides the System.out.println() method?
Answer: Option A
Explanation: System class contains out static field of type PrintStream
Q10
What is the purpose of the finalize() method?
Answer: Option A
Explanation: finalize() is called by garbage collector before object destruction