M251 Final - MCQs By/Waleed Omar
1. Programmers must include code to declare or handle any _______.
A. RunTimeException B. ArithmeticException
C. Checked Exceptions D. Unchecked Exceptions
2. When a class A inherits a class B, the methods of A can be …....
a. overridden b. overloaded c. inherited d. all of them
3. Which of the following is the concept that Java relies on for providing its
input/output facilities?
a. Import c. Variables
b. Packages d. Streams
4. Which of the following is an object of a class that implements a specific type of
listener interface and responds to an event?
a. An event listener c. An event source
b. An interface listener d. An interface source
5. Class members include:
a. instance variables c. reference variables
b. methods d. (a) and (b)
6. We can create neither instance variable nor object from……………
a. Interface b. Abstract class c. both a and b d. none
7. ______are useful in defining groups of classes related by inheritance.
a. packages c. abstract classes
b. interfaces d. None of the above
8. Which of the following GUI components are used for input of boolean values?
a. Text fields c. Check boxes
b. Buttons d. Combo boxes
9. Which of the following events occur when a button is pressed?
a. Item event c. Key event
b. Text event d. Action event
8. Which of the following classes is used to create objects that store web
addresses?
a. Socket c. URL
b. ServerSocket d. Scanner
Page 1
M251 Final - MCQs By/Waleed Omar
9. To which of the following Java packages does the class ArrayList belong?
a. java.lang c. java.swing
b. java.io d. java.util
10. An example of checked exceptions is_____.
a. RunTimeException c. Error
b. EOFException d. ArithmeticException
11. Which of the following statements could be includedin a Java interface?
a. public String name; c. public void setX(int n){name=n;}
b. public static int PI = 3.14; d. All of the above
12. Give the value of the following expression or indicate if there is an error: 4 % 2 + 5/0:
a. 2 c. 5
b. 0 d. Run-time error
13. Which of the following can be used to invoke a constructor of a class named
Robot from within this class?
a. Robot(1) c. this.set(1)
b. this(1) d. this.get(1)
14. Which of the following cannot be included in a Java interface?
a. reference variables c. abstract methods
b. constants d. All of the above
15. Which of the following is a Java method that causes a Java thread to enter the
blocked state?
a. sleep c. yield
b. run d. blocked
16. This operator == is used to
a. Compare object states c. Both (a) and (b)
b. Compare the references of the object d. None of the above
17. Which code might have generated the following?
a. Rectangle r2 = new Rectangle(r1);
b. Rectangle r1 = new Rectangle(5,9); Rectangle r2 = new Rectangle(5,9);
c. Rectangle r2 = new Rectangle(5,9); Rectangle r1 = r2;
Page 2
M251 Final - MCQs By/Waleed Omar
18. Which of the following exceptions must be caught or declared?
a. Error c. FileNotFoundException
b. RunTimeException d. All of the above
19. A class that does not allow creating objects of its type is called
a. final c. abstract
b. superclass d. static
20. Which part of the Java system makes decisions about which thread to run
next?
a. Javadoc c. main() method
b. Scheduler d. java interpreter
21. _______is used to define methods that carry out general functions not
associated with objects.
a. final c. private
b. static d. void
22. Which of the following is an object that responds to an event in an event
driven program?
a. An event source c. A layout manager
b. An event listener d. A container
23. Which of the following is a thread state that means the thread is ready to run,
but it’s not running yet?
a. Initial state c. Runnable state
b. Running state d. Blocked state
24. When ______ a method, its signature must stay the same.
A- overloading B overriding
C- calling D- inheriting
25. Which of the following do not store data but are used to point to objects?
a. Primitive variables c. Reference variables
b. Instance variables d. Static variables
26. _____ is a sequence of bytes, representing a flow of data from a source to a
destination.
a. Bytecode c. Event handling
b. Stream d. Source code
Page 3
M251 Final - MCQs By/Waleed Omar
27. Which of the following is used to encapsulate primitive data types and allow
them to be treated as objects?
a. Generic classes c. Interfaces
b. Adapter classes d. Object wrapper classes
28. Which of the following methods moves a Java thread from running state to
blocked state?
a. yield() b. sleep() c. block() d. destroy()
29- Which of these statements is correct to declare a constant in Java?
a. int x=9; c. public static int Numbers=10;
b. double y=9.0; d. public static final int ZONE=10;
29. Which of these states is a thread state which means the thread is ready to run
but it’s not running yet?
a. Initial state c. Running state
b. Runnable state d. Blocked state
30- Which of these methods is used for adding an item into ArrayList?
a. put() c. add()
b. write() d. print()
31- Which of these packages should be imported to use the PrintWriter class?
a. java.util c. javax.swing
b. java.io d. java.lang
73- Which of the following classes does not allow creating objects of its type?
a. interface c. static class
b. super class d. private class
32- Which of these methods is used for adding an item into HashMap?
a. add() c. write()
b. put() d. print()
33- API stands for:
a. Applet Package Interface c. Applet Programming Interface
b. Application Package Interchange d. Application Programming Interface
34- Which of the following is used to identify resources on the web?
a. number of channel c. host name
b. port number d. URL
Page 4
M251 Final - MCQs By/Waleed Omar
35. Which of the following notations is used to declare any of the Collection interfaces in
Java?
a. [ ] b. ( ) c. { } d. < >
36. Math.sqrt() is a ………………….
a. class method b. class variable c. instance method d.instance variable
37. …………………is an unordered collection which has no indexing, that contains no
duplicates and which has a dynamic size.
a. List b. Map c. Set d. Stack
38. Division by zero is an example of…………. error.
a. syntax b. compile-time c. run-time d.static semantic
39. A created instance of ………….. can call method add( ) to add elements to its
structure.
a. Map b. Set c. HashMap d. HashSet
40. The use of private access modifiers when declaring the instance variables of a class
is an example of:……………….
a. inheritance b. data hiding c. reuse d. encapsulation
41. Which of the following is not a bulk operation?
a. removeAll() b. retainAll() c. addAll() d. isEmpty()
42. One of the following does not belong to Collection framework.
a. Array b. List c. Set d. Map
43. A created instance of ………….. can call method add( ) to add elements to its
structure.
a. Map b. Set c. HashMap d. HashSet
44. . …………..is an indexable ordered collection of variable size that permits duplicate
elements.
a. Array b. Set Map d. List
45. One of the following is a common method in Collection sub-interfaces:
a. clear() b. add() c. reatinAll() d. contains()
Page 5