GATE-style MCQs
Module-1: Introduction, Inheritance & Exceptions (20 Questions)
Q1. Which of the following is true about Java bytecode?
a) It runs directly on hardware
b) It is machine-dependent
c) It runs on the JVM
d) It is only an interpreted language
Answer: c
Q2. Which of the following is NOT a Java Buzzword?
a) Portable
b) Secure
c) Machine-dependent
d) Object-oriented
Answer: c
Q3. Which of the following is NOT an OOP principle?
a) Encapsulation
b) Abstraction
c) Polymorphism
d) Recursion
Answer: d
Q4. Which operator is used for object reference comparison?
a) equals()
b) ==
c) =
d) compareTo()
Answer: b
Q5. What is the default value of a local variable in Java?
a) 0
b) null
c) Garbage value
d) Depends on type
Answer: c
Q6. Which keyword is used to prevent inheritance of a class?
a) static
b) final
c) abstract
d) super
Answer: b
Q7. Which keyword is used to call the parent class constructor?
a) this
b) super
c) parent
d) base
Answer: b
Q8. Which of the following supports multiple inheritance?
a) Classes
b) Abstract classes
c) Interfaces
d) Packages
Answer: c
Q9. What is the default access modifier for class members?
a) private
b) protected
c) default (package-private)
d) public
Answer: c
Q10. Which of the following statements about abstract classes is correct?
a) Cannot have constructors
b) Cannot have abstract methods
c) Cannot be instantiated
d) Must contain only static methods
Answer: c
Q11. Which type of exception is NOT checked at compile time?
a) IOException
b) SQLException
c) RuntimeException
d) FileNotFoundException
Answer: c
Q12. Which keyword is NOT used in exception handling?
a) try
b) catch
c) finally
d) finalize
Answer: d
Q13. Which of the following is true about method overloading?
a) Methods must have different return types only
b) Methods must have different names
c) Methods must differ in parameters
d) Methods must be in different classes
Answer: c
Q14. Which package is automatically imported in every Java program?
a) java.lang
b) java.io
c) java.util
d) java.net
Answer: a
Q15. Which keyword is used for garbage collection request?
a) delete
b) free
c) gc
d) System.gc()
Answer: d
Q16. Which method is called just before an object is garbage collected?
a) dispose()
b) finalize()
c) delete()
d) destroy()
Answer: b
Q17. Which statement about interfaces is correct?
a) They can have constructors
b) They can extend multiple interfaces
c) They cannot have variables
d) They cannot have default methods
Answer: b
Q18. Which keyword is used to re-throw an exception?
a) catch
b) throw
c) throws
d) final
Answer: b
Q19. Which of the following exceptions is unchecked?
a) NullPointerException
b) IOException
c) InterruptedException
d) SQLException
Answer: a
Q20. Which of the following is true about String in Java?
a) Mutable and final
b) Immutable and final
c) Mutable and non-final
d) None of the above
Answer: b
Module-2: Multithreading, Collections & Swing (20 Questions)
Q21. Which method starts a thread in Java?
a) run()
b) start()
c) init()
d) execute()
Answer: b
Q22. Which of the following is NOT a thread state?
a) Running
b) Ready
c) Dead
d) Waiting
Answer: b
Q23. Which of the following ensures that only one thread can access a resource at a time?
a) Synchronization
b) Serialization
c) Deadlock
d) Thread priority
Answer: a
Q24. Which method is used for inter-thread communication?
a) stop()
b) wait()
c) exit()
d) terminate()
Answer: b
Q25. Which of the following collections allows duplicate elements?
a) HashSet
b) TreeSet
c) ArrayList
d) Hashtable
Answer: c
Q26. Which collection is synchronized?
a) HashMap
b) Vector
c) ArrayList
d) HashSet
Answer: b
Q27. Which is NOT part of Java Collection Framework?
a) List
b) Map
c) Queue
d) Stream
Answer: d
Q28. Which of the following is fail-fast?
a) Enumeration
b) Iterator
c) ListIterator
d) None of the above
Answer: b
Q29. Which of the following orders elements naturally?
a) HashMap
b) TreeSet
c) HashSet
d) Hashtable
Answer: b
Q30. Which of the following allows null keys?
a) Hashtable
b) HashMap
c) TreeMap
d) None of the above
Answer: b
Q31. Which layout manager is default for JFrame?
a) FlowLayout
b) BorderLayout
c) GridLayout
d) CardLayout
Answer: b
Q32. Which method is used to set the title of a JFrame?
a) setText()
b) setTitle()
c) setLabel()
d) setCaption()
Answer: b
Q33. Which Swing component is used for multiple-choice selection?
a) JTextField
b) JButton
c) JCheckBox
d) JLabel
Answer: c
Q34. Which event is generated when a button is clicked?
a) ItemEvent
b) ActionEvent
c) KeyEvent
d) MouseEvent
Answer: b
Q35. Which Swing component is best for displaying multiple tabs?
a) JList
b) JTabbedPane
c) JComboBox
d) JTable
Answer: b
Q36. Which of the following is a lightweight container in Swing?
a) JFrame
b) JPanel
c) JWindow
d) JDialog
Answer: b
Q37. Which of the following is NOT true about Swing?
a) Platform-independent
b) Lightweight
c) Uses peer components
d) Based on MVC architecture
Answer: c
Q38. Which method is used to repaint a Swing component?
a) update()
b) repaint()
c) refresh()
d) redraw()
Answer: b
Q39. Which collection class allows retrieval of elements based on insertion order?
a) HashSet
b) TreeSet
c) LinkedHashSet
d) Hashtable
Answer: c
Q40. Which thread method cannot be overridden?
a) run()
b) start()
c) sleep()
d) wait()
Answer: b