Objects and Collections Questions and Answers
Java Objects and Collections programming questions and answers are essential for mastering object-oriented design and data structure handling. These questions often appear in coding interviews by Infosys, TCS, and Accenture. The topic covers object creation, reference handling, garbage collection, and the use of Java Collection Framework classes like List, Set, and Map. Understanding how to manage and iterate over collections efficiently helps in building optimized programs. Practicing programming questions and answers in this area enhances both logic and coding speed—crucial skills for clearing technical interview rounds and online assessments.
Objects and Collections
Showing 10 of
38 questions
11. /* 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?
- No statement required.
- import java.io.*;
- include java.io.*;
- import java.io.PrintWriter;
12. What is the numerical range of char?
- 0 to 32767
- 0 to 65535
- -256 to 255
- -32768 to 32767
13. Which of the following are Java reserved words? run import default implement
- 1 and 2
- 2 and 3
- 3 and 4
- 2 and 4
15. Which method is called automatically when an object is created?
- finalize()
- start()
- constructor
- main()
16. Which collection class stores elements in key-value pairs?
- List
- Set
- Map
- Queue
19. Which of the following guarantees unique elements?
- ArrayList
- HashSet
- LinkedList
- Vector
20. Which method is used to compare two strings?
- compare()
- equals()
- match()
- same()