Objects and Collections Questions and Answers

Practice Mode
Showing 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?
  • A No statement required.
  • B import java.io.*;
  • C include java.io.*;
  • D import java.io.PrintWriter;
Answer: Option A
Q12
What is the numerical range of char?
  • A 0 to 32767
  • B 0 to 65535
  • C -256 to 255
  • D -32768 to 32767
Answer: Option B
Q13
Which of the following are Java reserved words?     run     import     default     implement
  • A 1 and 2
  • B 2 and 3
  • C 3 and 4
  • D 2 and 4
Answer: Option B
Q14
Which keyword is used to create an object in Java?
  • A class
  • B new
  • C this
  • D object
Answer: Option B
Explanation: The new keyword allocates memory and creates objects.
Q15
Which method is called automatically when an object is created?
  • A finalize()
  • B start()
  • C constructor
  • D main()
Answer: Option C
Explanation: A constructor initializes an object when it is created.
Q16
Which collection class stores elements in key-value pairs?
  • A List
  • B Set
  • C Map
  • D Queue
Answer: Option C
Explanation: A Map stores data as key-value pairs.
Q17
Which interface allows duplicate elements?
  • A Set
  • B Map
  • C List
  • D Iterator
Answer: Option C
Explanation: A List allows duplicate values.
Q18
Which class is synchronized?
  • A ArrayList
  • B LinkedList
  • C Vector
  • D HashSet
Answer: Option C
Explanation: Vector is synchronized by default.
Q19
Which of the following guarantees unique elements?
  • A ArrayList
  • B HashSet
  • C LinkedList
  • D Vector
Answer: Option B
Explanation: A HashSet does not allow duplicate elements.
Q20
Which method is used to compare two strings?
  • A compare()
  • B equals()
  • C match()
  • D same()
Answer: Option B
Explanation: equals() checks the value equality of strings.
Questions and Answers for Competitive Exams Various Entrance Test