0% found this document useful (0 votes)
16 views

Comprehensive_Java_Test_Final

Uploaded by

Nicolae Altomi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Comprehensive_Java_Test_Final

Uploaded by

Nicolae Altomi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Comprehensive Java Test

This test contains 80 multiple-choice questions based on various Java topics. Each question
has one correct answer. Answers are provided at the end of the document.

1. What does AWT stand for in Java?

 A) Abstract Window Toolkit


 B) Advanced Window Tools
 C) Application Window Toolkit
 D) Abstract Widget Toolkit

2. Which class in AWT is used to create a button?

 A) JButton
 B) Button
 C) ClickButton
 D) ActionButton

3. What method is used to add an ActionListener to a button in AWT?

 A) addAction
 B) setActionListener
 C) addActionListener
 D) actionPerformed

4. Which layout arranges components in a grid of equally sized cells?

 A) FlowLayout
 B) GridLayout
 C) BorderLayout
 D) CardLayout

5. What is the default alignment for components in a FlowLayout?

 A) Left
 B) Center
 C) Right
 D) Top

6. An abstract class in Java must have which of the following?

 A) At least one abstract method


 B) A constructor
 C) Static methods only
 D) It is optional to have an abstract method
7. What keyword is used to declare an abstract class in Java?

 A) interface
 B) abstract
 C) extends
 D) implements

8. If a class extends an abstract class, it must:

 A) Override all abstract methods in the superclass


 B) Be declared final
 C) Be declared abstract
 D) Implement only some methods

9. What does an interface in Java primarily contain?

 A) Static methods
 B) Abstract methods
 C) Constructors
 D) Instance variables

10. Which keyword is used for a class to use an interface?

 A) extends
 B) implements
 C) uses
 D) inherits

11. What happens if a class does not implement all methods of an interface?

 A) It will compile with warnings


 B) It must be declared abstract
 C) The unimplemented methods are ignored
 D) It will not compile

12. What is the purpose of the `init()` method in an applet?

 A) To initialize applet resources


 B) To start applet execution
 C) To handle user input
 D) To draw graphics

13. Which tag is used to embed an applet in an HTML page?

 A) <java>
 B) <embed>
 C) <applet>
 D) <script>
14. What method is called when an applet is terminated?

 A) start()
 B) stop()
 C) destroy()
 D) end()

15. Which interface is used to handle action events?

 A) EventListener
 B) ActionListener
 C) FocusListener
 D) ItemListener

16. Which method is used to detect when a button is clicked?

 A) buttonClicked()
 B) actionPerformed()
 C) itemStateChanged()
 D) focusLost()

17. The MouseMotionListener interface includes which of the following methods?

 A) mouseClicked()
 B) mouseMoved()
 C) mouseEntered()
 D) mouseExited()

18. Which statement is used to import a package in Java?

 A) include
 B) package
 C) import
 D) using

19. What is the purpose of the `import static` statement?

 A) Import all static methods and fields


 B) Import static classes only
 C) Import private members
 D) Import dynamic content

20. If no package statement is included, the class is placed in which package?

 A) java.lang
 B) Default
 C) Global
 D) Unnamed
21. What is the primary difference between a TextField and a TextArea?

 A) TextField allows editing, TextArea does not


 B) TextField is for single-line input, TextArea is for multi-line input
 C) TextArea is read-only, TextField is not
 D) None of the above

22. Which method is used to set text in a TextField?

 A) setText()
 B) addText()
 C) insertText()
 D) appendText()

23. Which method appends text to a TextArea?

 A) setText()
 B) append()
 C) addText()
 D) appendText()

24. What is the result of calling `frame.setResizable(false)` on a Frame?

 A) The frame becomes maximized


 B) The frame cannot be resized by the user
 C) The frame is hidden
 D) The frame's layout changes

25. Which method in AWT is used to repaint a component?

 A) draw()
 B) paint()
 C) repaint()
 D) update()

26. What does the `drawOval()` method do?

 A) Draws a rectangle
 B) Draws an ellipse within a specified rectangle
 C) Draws a circle only
 D) Draws a polygon

27. Which Graphics method is used to draw an arc?

 A) drawArc()
 B) drawLine()
 C) drawCircle()
 D) drawOval()
28. What is the default font in Java's Graphics?

 A) Serif
 B) SansSerif
 C) Dialog
 D) Monospaced

29. Which layout manager arranges components in a left-to-right flow?

 A) FlowLayout
 B) GridLayout
 C) BorderLayout
 D) CardLayout

30. What is the default layout manager for a Panel?

 A) FlowLayout
 B) GridLayout
 C) BorderLayout
 D) CardLayout

31. In BorderLayout, how many regions can you add components to?

 A) 3
 B) 4
 C) 5
 D) 6

32. Which constructor of GridLayout is used to set horizontal and vertical gaps?

 A) GridLayout()
 B) GridLayout(int rows, int columns)
 C) GridLayout(int rows, int columns, int hgap, int vgap)
 D) None of the above

33. What happens if you try to instantiate an abstract class directly?

 A) It throws a runtime error


 B) It throws a compilation error
 C) It runs normally
 D) It creates an object of the superclass

34. What is the purpose of an abstract method?

 A) Provide implementation for all methods


 B) Force subclasses to implement it
 C) Allow multiple inheritance
 D) None of the above
35. Can an interface extend another interface in Java?

 A) Yes
 B) No
 C) Only for public interfaces
 D) Only if no methods are implemented

36. Which keyword is used to define a constant in an interface?

 A) final
 B) static
 C) public
 D) None (it is implicit)

37. Can an interface have a static method?

 A) Yes
 B) No
 C) Only in abstract classes
 D) Only with a default method

38. Which lifecycle method of an applet is called every time the user visits the applet's page?

 A) init()
 B) start()
 C) stop()
 D) destroy()

39. How can you terminate an applet explicitly?

 A) Using System.exit()
 B) Using the destroy() method
 C) Using the stop() method
 D) None of the above

40. What is the tag to define an applet's height and width in HTML?

 A) <applet size>
 B) <applet dimension>
 C) <applet>
 D) <object>

41. Which method is used to handle window closing events?

 A) windowActivated()
 B) windowClosed()
 C) windowClosing()
 D) windowDeactivated()
42. What is returned by the `getModifiers()` method of a KeyEvent?

 A) The key's state


 B) The key's ASCII value
 C) The modifier keys pressed
 D) The event source

43. Which listener detects when the mouse enters a component's area?

 A) MouseListener
 B) MouseMotionListener
 C) FocusListener
 D) ActionListener

44. What is the benefit of organizing classes into packages?

 A) Code readability
 B) Avoiding name conflicts
 C) Faster execution
 D) More accessible debugging

45. How do you import all classes from a package named `utilities`?

 A) import utilities
 B) import utilities.*
 C) import all.utilities
 D) import utilities.all

46. Which package is automatically imported into every Java program?

 A) java.util
 B) java.lang
 C) java.awt
 D) javax.swing

47. What is the purpose of the `paint()` method in an applet?

 A) To handle window events


 B) To draw graphics
 C) To execute JavaScript
 D) To manage applet lifecycle

48. How is a Frame in AWT different from a Panel?

 A) A Frame has a title and border


 B) A Panel can contain other Panels
 C) A Frame is resizable
 D) All of the above
49. Which class provides methods for drawing graphics in AWT?

 A) java.awt.Component
 B) java.awt.Graphics
 C) java.awt.Canvas
 D) java.awt.Image

50. What is the difference between `drawRect()` and `fillRect()` in Graphics?

 A) drawRect() draws an outline, fillRect() fills the rectangle


 B) Both perform the same operation
 C) fillRect() requires less memory
 D) drawRect() is used only in applets

51. Which exception is thrown when a thread sleeps for too long in Java?

 A) InterruptedException
 B) IllegalThreadStateException
 C) ArithmeticException
 D) None

52. What is the main advantage of using interfaces in Java?

 A) Faster execution
 B) Supports multiple inheritance
 C) Allows direct object creation
 D) Improves memory management

Answer Key
1. A

2. B

3. C

4. B

5. B

6. D

7. B

8. A

9. B

10. B
11. B

12. A

13. C

14. C

15. B

16. B

17. B

18. C

19. A

20. D

21. B

22. A

23. B

24. B

25. C

26. B

27. A

28. C

29. A

30. A

31. C

32. C

33. B

34. B

35. A

36. D
37. A

38. B

39. B

40. C

41. C

42. C

43. A

44. B

45. B

46. B

47. B

48. D

49. B

50. A

51. A

52. B

You might also like