Java All Chapters MCQ
Java All Chapters MCQ
1. The most basic circuitry-level computer language, which consists of on and off
switches, is
a. a high-level language
b. machine language
c. the Java programming language
d. C++
2. Languages that let you use a vocabulary of descriptive terms such as “read,” “write,”
or “add” are known as languages.
a. high-level
b. machine
c. procedural
d. object-oriented
6. For convenience, the individual operations used in a computer program are often
grouped into logical units called
a. procedures
b. variables
c. constants
d. logistics
7. Envisioning program components as objects that are similar to concrete objects in
the real world is the hallmark of
a. command-line operating systems
b. procedural programming
c. object-oriented programming
d. machine languages
11. You must compile programs written in the Java programming language into
a. bytecode
b. source code
c. javadoc statements
d. object code
14. In a Java program, you must use ______ to separate classes, objects, and methods.
a. commas
b. semicolons
c. periods
d. forward slashes
17. The Java programming language supports three types of comments: ________, ________,
and javadoc.
a. line, block
b. string, literal
c. constant, variable
d. single, multiple
18. After you write and save a program file, you ______ it.
a. interpret and then compile
b. interpret and then execute
c. compile and then resave
d. compile and then interpret
20. You save text files containing Java language source code using the file extension
a. .java
b. .class
c. .txt
d. .src
2. Which of the following is not a primitive data type in the Java programming
language?
a. Boolean
b. byte
c. int
d. sector
5. Which of the following values can you assign to a variable of type int?
a. 0
b. 98.6
c. ‘S’
d. 5,000,000,000,000
6. Which of the following data types can store a value in the least amount of memory?
a. short
b. long
c. int
d. byte
11. If a variable named salary holds a floating-point value, then the statement int wages
= (int) salary; is an example of
a. primitive conversion
b. assignment
c. coercion
d. casting
14. The correct way to declare a String variable that holds “hello” is
a. String greeting = hello;
b. char greeting = “hello”;
c. String greeting = ‘hello’;
d. String greeting = "hello";
1. The portion of a program within which you can reference a variable is its
a. range
b. space
c. domain
d. scope
14. When you create more than one method in a class with the same name, but with
different arguments, the methods are
a. overridden
b. duplicated
c. overloaded
d. abstracted
5. When a Boolean expression includes multiple operators, they are evaluated in which
order by default?
a. left to right
b. right to left
c. according to precedence
d. from outside parentheses inward
9. In an if-else statement, when the Boolean expression is true, the else portion is
a. executed
b. skipped
c. compiled
d. ignored
10. In Java, blocks of statements within control structures are enclosed within
a. square brackets
b. parentheses
c. curly braces
d. angle brackets
3. The three types of loops supported in the Java programming language are
a. for, foreach, switch
b. while, do, repeat
c. while, do...while, for
d. until, for, repeat
4. A pretest loop
a. evaluates the condition after the loop body executes
b. evaluates the condition before any loop body executes
c. executes only once
d. is illegal in Java
7. A loop that performs one or more statements before checking the condition is a
a. while loop
b. do...while loop
c. for loop
d. control loop
15. A loop that should execute exactly five times must contain a
a. Boolean flag
b. loop control variable
c. break statement
d. nested decision
16. To stop a loop from executing based on a condition inside the loop, use
a. stop
b. return
c. break
d. go
17. A Boolean variable that controls loop execution is called a
a. controller
b. test variable
c. flag
d. guard
10. When you use a loop to access array elements, it must run
a. from 1 to length
b. from 0 to length - 1
c. from 0 to length
d. until a match is found
12. To avoid exceeding array bounds, make sure that the index is
a. positive
b. initialized
c. less than the array length
d. not declared in the loop
5. If you declare two String objects as String word1 = new String("happy"); and String
word2 = new String("happy");, then the value of word1 == word2 is
a. true
b. false
c. illegal
d. unknown
6. If you declare two String objects as String word1 = new String("happy"); and String
word2 = new String("happy");, then the value of word1.equals(word2) is
a. true
b. false
c. illegal
d. unknown
7. The method that determines whether two String objects are equivalent, regardless
of case, is
a. equalsNoCase()
b. toUpperCase()
c. equalsIgnoreCase()
d. equals()
9. If you create two String objects using String name1 = new String("Jordan"); and
String name2 = new String("Jore");, then name1.compareTo(name2) has a value of
a. true
b. false
c. -1
d. 1
10. If String myFriend = new String("Ginny");, then which of the following has the value
1?
a. myFriend.compareTo("Gabby");
b. myFriend.compareTo("Gabriella");
c. myFriend.compareTo("Ghazala");
d. myFriend.compareTo("Hammie");
11. If String movie = new String("West Side Story");, then the value of
movie.indexOf('s') is
a. true
b. false
c. 2
d. 3
Chapter 8 – Arrays
4. The statement int[] value = new int[34]; reserves memory for how many integers?
a. 0
b. 33
c. 34
d. 35
5. A(n) ___ contained within square brackets is used to indicate one of an array’s
elements.
a. character
b. double
c. integer
d. string
Chapter 9 – Applets
2. A program that allows you to display HTML documents on your computer screen is
a
a. search engine
b. compiler
c. browser
d. server
3. The name of any Swing applet called using CODE within an HTML document must
use the ___ extension.
a. .exe
b. .code
c. .java
d. .class
13. When a Swing applet is registered as a listener with a JButton, if a user clicks the
JButton, the method that executes is
a. buttonPressed()
b. addActionListener()
c. start()
d. actionPerformed()
14. When you write a method that has the same method header as an automatically
provided method, you ___ the original version.
a. destroy
b. override
c. call
d. copy
15. Which of the following statements creates a JLabel that says “Welcome”?
a. JLabel = new JLabel("Welcome");
b. JLabel aLabel = JLabel("Welcome");
c. aLabel = new JLabel("Welcome");
d. JLabel aLabel = new JLabel("Welcome");
18. In a window that is 200 x 200 pixels, position 10, 190 is nearest to the ___ corner.
a. upper-left
b. upper-right
c. lower-left
d. lower-right
19. An object’s method ___ can be used to determine the component that sends an event.
a. getSource()
b. instanceof()
c. both of the above
d. none of the above
Chapter 10 – Graphics
4. If you use the setColor() method to change a Graphics object’s color to yellow, ___
will appear in yellow.
a. only the next graphics output
b. all graphics output for the remainder of the method
c. all graphics output for the remainder of the applet
d. all graphics output until you change the color
7. If you draw an oval with the same value for width and height, then you draw a(n)
a. circle
b. square
c. rounded square
d. ellipsis
8. The zero-degree position for any arc is at the ___ o’clock position.
a. three
b. six
c. nine
d. twelve
10. You use the method ___ to copy any rectangular area to a new location.
a. copyRect()
b. copyArea()
c. repeatRect()
d. repeatArea()
11. The measurement of an uppercase character from the baseline to the top of the
character is its
a. ascent
b. descent
c. leading
d. height
12. To be sure that a vertical series of Strings has enough room to appear in an applet,
you would use which of the following statements?
a. g.drawString("Some string", x, y += g.getFontMetrics().getHeight());
b. g.drawString("Some string", x, y += g.getFontMetrics().getLeading());
c. g.drawString("Some string", x, y += g.getFontMetrics().getAscent());
d. g.drawString("Some string", x, y += g.getFontMetrics().getDescent());
13. You can discover the fonts that are available on your system by using the
a. getAllFonts() method of the GraphicsEnvironment class
b. getAllFonts() method of the Graphics class
c. setAllFonts() method of the GraphicsEnvironment class
d. getAllFonts() method of the ImageEnvironment class
16. Java 2D uses ___ when creating and drawing a 2D drawing object.
a. only coordinate space
b. only user coordinate space
c. both coordinate and user coordinate space
d. only 2D coordinate space
18. After the getAudioClip() method retrieves a sound object named mysound, the ___
plays a sound continually in a Swing applet.
a. sound.loop() method
b. loop() method
c. mysound.loop() method
d. mysound.continuous() method
19. The ___ is particularly useful for loading an image into either an applet or
application.
a. Image class
b. ImageLogo class
c. ImageIcon class
d. GetImage class
1. ___ is an alternate way(s) to discover which of two classes is the base class or
subclass.
a. Look at the class size
b. Try saying the two class names together
c. Use polymorphism
d. Both a and b are correct
4. Which of the following choices most closely describes a parent class/child class
relationship?
a. Rose/Flower
b. Present/Gift
c. Dog/Poodle
d. Sparrow/Bird
6. A class named Building has a method named getFloors(). If School is a child class of
Building, and ModelHigh is an object of type School, then which of the following
statements is valid?
a. Building.getFloors();
b. School.getFloors();
c. ModelHigh.getFloors();
d. All of the above statements are valid
8. When a subclass method has the same name and argument types as a superclass
method, the subclass method can ___ the superclass method.
a. override
b. overuse
c. overload
d. overcompensate
9. When you instantiate an object that is a member of a subclass, the ___ constructor
executes first.
a. subclass
b. child class
c. extended class
d. parent class
10. The keyword super always refers to the ___ of the class in which you use it.
a. child class
b. derived class
c. sub class
d. parent class
13. A child class Motorcycle extends a parent class Vehicle. Each class constructor
requires one String argument. The Motorcycle class constructor can call the Vehicle
class constructor with the statement
a. Vehicle("Honda");
b. Motorcycle("Harley");
c. super("Suzuki");
d. none of the above
14. In the Java programming language, the concept of keeping data private is known as
a. polymorphism
b. information hiding
c. data deception
d. concealing fields
15. If you create a data field or method that is ___, it can be used within its own class or
in any classes extended from that class.
a. public
b. protected
c. private
d. none of the above
18. You use final as a method access modifier when you create methods for which you
want to prevent overriding.
a. class
b. superclass
c. subclass
d. instance
20. You use ___ as a method access modifier when you create class methods for which
you want to prevent overriding.
a. final
b. static
c. private
d. public
4. An abstract class Product has two subclasses, Perishable and NonPerishable. None
of the constructors for these classes requires any arguments. Which of the following
statements is legal?
a. Product myProduct = new Product();
b. Perishable myProduct = new Product();
c. NonPerishable myProduct = new NonPerishable();
d. none of the above
5. An abstract class Employee has two subclasses, Permanent and Temporary. The
Employee class contains an abstract method named setType(). Before you can
instantiate Permanent or Temporary objects, which of the following must be true?
a. You must code statements for the setType() method within the Permanent class.
b. You must code statements for the setType() method within both the Permanent
and the Temporary classes.
c. You must not code statements for the setType() method within either class.
d. You may code statements in one but not both of the subclasses.
6. When you create a superclass and one or more subclasses, each object of the
subclass ___ superclass object.
a. overrides the
b. “is a”
c. “is not a”
d. is a new
8. When you create a ___, you create a variable name in which you can hold the
memory address of an object.
a. class
b. superclass
c. subclass
d. reference
9. The program’s ability to select the correct subclass method to execute is known as
___ method binding.
a. polymorphic
b. dynamic
c. early
d. intelligent
11. You ___ override the toString() method in any class you create.
a. cannot
b. can
c. must
d. must implement StringListener to
15. Java subclasses have the ability to inherit from ___ parent class(es).
a. one
b. two
c. multiple
d. no
17. When you create a class that uses an interface, you include the keyword ___ in the
class header.
a. interface
b. implements
c. accouterments
d. listener
20. To provide data or behavior that can be inherited but overridden, you should write
a
a. abstract class
b. interface
c. final superclass
d. concrete object
Chapter 13 – File Input and Output
1. Files always
a. hold software instructions
b. occupy a section of storage space
c. remain open during the execution of a program
d. all of the above
3. The ___ package contains all the classes you use in file processing.
a. java.file
b. java.io
c. java.lang
d. java.process
6. Data used by businesses is stored in a data hierarchy that includes the following
items, from largest to smallest:
a. file, field, record, character
b. record, file, field, character
c. file, record, field, character
d. record, field, file, character
9. Before a program can use a data file, the program must ___ the file.
a. create
b. open
c. store
d. close
10. When you perform an input operation in a Java program, you use a
a. pipeline
b. channel
c. moderator
d. stream
12. The output from System.err and System.out go to the same device
a. must
b. cannot
c. might
d. might on a mainframe system, but never would on a PC
15. Much of the data that you write with DataOutputStream objects is not readable in a
text editor because
a. it does not exist in any physical sense
b. it is stored in a non-character format
c. you can read it only with a special piece of hardware called a Data Reader
d. Java’s security features prohibit it
4. Which is the correct syntax for adding a JButton named b1 to a Container named con
when using CardLayout?
a. con.add(b1);
b. con.add("b1");
c. con.add("Options", b1);
d. none of the above
5. You can use the ___ class to arrange components in a single row or column of a
container.
a. FlowLayout
b. BorderLayout
c. CardLayout
d. BoxLayout
6. When you use a ___, the components you add fill their region; they do not retain their
default size.
a. FlowLayout
b. BorderLayout
c. FixedLayout
d. RegionLayout
11. A JPanel is a
a. Window
b. Container
c. both of the above
d. none of the above
12. The ___ class allows you to arrange components as if they are stacked like index or
playing cards.
a. GameLayout
b. CardLayout
c. BoxLayout
d. GridBagLayout
19. You can use the ___ method to determine the Object where an ActionEvent
originates.
a. getObject()
b. getEvent()
c. getOrigin()
d. getSource()
4. The method that ends the current application and returns control to the operating
system is
a. System.end()
b. System.done()
c. System.exit()
d. System.abort()
8. The segment of code that handles or takes appropriate action following an exception
is a ___ block.
a. try
b. catch
c. throws
d. handles
10. If you try three statements and include three catch blocks, and the second try
statement throws an Exception, then
a. the first catch block executes
b. the first two catch blocks execute
c. only the second catch block executes
d. the first matching catch block executes
11. When a try block does not generate an Exception and you have included multiple
catch blocks,
a. they all execute
b. only the first one executes
c. only the first matching one executes
d. no catch blocks execute
12. The catch block that begins catch(Exception e) can catch Exceptions of type
a. IOException
b. ArithmeticException
c. both of the above
d. none of the above
13. The code within a finally block executes when the try block
a. identifies one or more Exceptions
b. does not identify any Exceptions
c. either a or b
d. neither a nor b
17. When you use any method, you must know three pieces of information to use the
method to its full potential; but you don’t need to know
a. the method’s return type
b. the type of arguments the method requires
c. the number of statements within the method
d. the type of Exceptions the method throws
18. The memory location where the computer stores the list of locations to which the
system must return is known as the
a. registry
b. call stack
c. chronicle
d. archive
19. You can get a list of the methods through which an Exception has traveled by using
the method
a. getMessage()
b. callStack()
c. getPath()
d. printStackTrace()
Chapter 16 – File Input and Output
1. Files always
a. hold software instructions
b. occupy a section of storage space
c. remain open during the execution of a program
d. all of the above
3. The ___ package contains all the classes you use in file processing.
a. java.file
b. java.io
c. java.lang
d. java.process
6. Data used by businesses is stored in a data hierarchy that includes the following
items, from largest to smallest:
a. file, field, record, character
b. record, file, field, character
c. file, record, field, character
d. record, field, file, character
9. Before a program can use a data file, the program must ___ the file.
a. create
b. open
c. store
d. close
10. When you perform an input operation in a Java program, you use a
a. pipeline
b. channel
c. moderator
d. stream
12. The output from System.err and System.out go to the same device
a. must
b. cannot
c. might
d. might on a mainframe system, but never would on a PC
15. Much of the data that you write with DataOutputStream objects is not readable in a
text editor because
a. it does not exist in any physical sense
b. it is stored in a non-character format
c. you can read it only with a special piece of hardware called a Data Reader
d. Java’s security features prohibit it
18. Which of the following applications is most likely to use random file processing?
a. a program that schedules airline reservations
b. a credit card company’s end-of-month billing program
c. a college’s program that lists honor students at the end of each semester
d. a manufacturing company’s quarterly inventory reporting system
19. The method that the RandomAccessFile class contains that does not exist in the
InputStream class is
a. read()
b. close()
c. seek()
d. delete()