Objects and Collections Questions and Answers
Practice ModeShowing 10 of 38 questions
Q11
/* Missing Statement ? */
public class foo
{
public static void main(String[]args)throws Exception
{
java.io.PrintWriter out = new java.io.PrintWriter();
new java.io.OutputStreamWriter(System.out,true);
out.println("Hello");
}
}
What line of code should replace the missing statement to make this program compile?
Answer: Option A
Q12
What is the numerical range of char?
Answer: Option B
Q13
Which of the following are Java reserved words?
run
import
default
implement
Answer: Option B
Q14
Which keyword is used to create an object in Java?
Answer: Option B
Explanation: The new keyword allocates memory and creates objects.
Q15
Which method is called automatically when an object is created?
Answer: Option C
Explanation: A constructor initializes an object when it is created.
Q16
Which collection class stores elements in key-value pairs?
Answer: Option C
Explanation: A Map stores data as key-value pairs.
Q17
Which interface allows duplicate elements?
Answer: Option C
Explanation: A List allows duplicate values.
Q18
Which class is synchronized?
Answer: Option C
Explanation: Vector is synchronized by default.
Q19
Which of the following guarantees unique elements?
Answer: Option B
Explanation: A HashSet does not allow duplicate elements.
Q20
Which method is used to compare two strings?
Answer: Option B
Explanation: equals() checks the value equality of strings.