0% found this document useful (0 votes)
27 views41 pages

Java All Chapters MCQ

The document contains multiple-choice questions covering various chapters of Java programming, including topics such as basic programming concepts, data types, methods, classes, control structures, and loops. Each chapter presents a series of questions designed to test knowledge and understanding of Java programming principles. The questions range from fundamental concepts to more advanced topics, providing a comprehensive review of Java programming skills.

Uploaded by

gimeon2512
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views41 pages

Java All Chapters MCQ

The document contains multiple-choice questions covering various chapters of Java programming, including topics such as basic programming concepts, data types, methods, classes, control structures, and loops. Each chapter presents a series of questions designed to test knowledge and understanding of Java programming principles. The questions range from fundamental concepts to more advanced topics, providing a comprehensive review of Java programming skills.

Uploaded by

gimeon2512
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

Java Multiple Choice Questions (All Chapters)

Chapter 1: Review Questions

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

3. The rules of a programming language constitute its


a. objects
b. logic
c. format
d. syntax

4. A translates high-level language statements into machine code.


a. programmer
b. syntax detector
c. compiler
d. decipherer

5. Computer memory locations are called


a. compilers
b. variables
c. addresses
d. appellations

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

8. An object’s attributes also are known as its


a. states
b. orientations
c. methods
d. procedures

9. An instance of a(n) ______ inherits its attributes from it.


a. object
b. procedure
c. method
d. class

10. The Java programming language is architecturally


a. specific
b. oriented
c. neutral
d. abstract

11. You must compile programs written in the Java programming language into
a. bytecode
b. source code
c. javadoc statements
d. object code

12. All Java programming language statements must end with a


a. period
b. comma
c. semicolon
d. closing parenthesis

13. Arguments to methods always appear within


a. parentheses
b. double quotation marks
c. single quotation marks
d. curly braces

14. In a Java program, you must use ______ to separate classes, objects, and methods.
a. commas
b. semicolons
c. periods
d. forward slashes

15. All Java programs must have a method named


a. method()
b. main()
c. java()
d. Hello()

16. Nonexecuting program statements that provide documentation are called


a. classes
b. notes
c. comments
d. commands

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

19. The command to execute a compiled program is


a. run
b. execute
c. javac
d. java

20. You save text files containing Java language source code using the file extension
a. .java
b. .class
c. .txt
d. .src

21. The Java Virtual Machine, or JVM, refers to a(n)


a. interpreter
b. operating system
c. hypothetical computer
d. compiler
Chapter 2: Review Questions

1. When data cannot be changed after a program is compiled, the data is


a. constant
b. variable
c. volatile
d. mutable

2. Which of the following is not a primitive data type in the Java programming
language?
a. Boolean
b. byte
c. int
d. sector

3. Which of the following elements is not required in a variable declaration?


a. a type
b. an identifier
c. an assigned value
d. a semicolon

4. The assignment operator in the Java programming language is


a. =
b. ==
c. :=
d. ::

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

7. The modulus operator


a. is represented by a forward slash
b. provides the remainder of integer division
c. provides the remainder of floating-point division
d. Answers b. and c. are correct
8. According to the rules of operator precedence, division always takes place prior to
a. multiplication
b. modulus
c. subtraction
d. Answers a. and b. are correct

9. A Boolean variable can hold


a. any character
b. any whole number
c. true or false
d. any numeric value

10. A floating-point variable


a. can contain a decimal portion
b. can never contain a decimal portion
c. cannot be used in arithmetic operations
d. must be declared as an integer

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

12. The value 3.5 is of type


a. float
b. int
c. double
d. char

13. Which of the following is a valid char assignment?


a. char x = ‘ab’;
b. char x = “a”;
c. char x = ‘a’;
d. char x = a;

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";

15. Escape sequences begin with


a. a percent sign
b. an asterisk
c. a backslash
d. a forward slash

16. A literal String in Java appears


a. between single quotation marks
b. between parentheses
c. between double quotation marks
d. within angle brackets

17. The Unicode character set uses


a. 8-bit characters
b. 10-bit characters
c. 16-bit characters
d. 24-bit characters

18. The String class method length()


a. counts the number of characters in a String
b. counts the number of words in a String
c. returns a float value
d. returns the size in bytes of a String

19. Which of the following is true about using variables in Java?


a. They don’t need to be declared before use
b. You can change the data type of a variable at runtime
c. Each variable must be declared with a specific data type
d. Variables can only store numeric data

Chapter 3: Review Questions – Using Methods, Classes, and Objects

1. The portion of a program within which you can reference a variable is its
a. range
b. space
c. domain
d. scope

2. A variable declared within a method is


a. private
b. public
c. local
d. global

3. Variables declared within a method are destroyed when


a. the method ends
b. the object is deleted
c. the method is compiled
d. the method is called again

4. Methods provide all of the following benefits except


a. clarity
b. reusability
c. portability
d. encapsulation

5. The variables you use in a method call are called


a. arguments
b. parameters
c. declarations
d. types

6. The variables you use in a method declaration are called


a. arguments
b. parameters
c. declarations
d. types

7. When you call a method and pass an argument,


a. the method changes the original variable’s value
b. the method creates a copy of the variable’s value
c. the method ignores the value
d. none of the above

8. When you pass a reference variable to a method,


a. a copy of the object’s memory address is made
b. a new object is created
c. the original object is deleted
d. the reference variable becomes a primitive variable

9. You define a class using the keyword


a. Class
b. class
c. package
d. public

10. The variables declared within a class are called


a. references
b. methods
c. parameters
d. fields
11. An object’s methods are also called its
a. fields
b. behaviors
c. instances
d. signatures

12. A method that creates and initializes an object is a


a. constructor
b. constructor method
c. initializer
d. class creator

13. A constructor method


a. must be public
b. has no return type
c. must have a return type
d. must return a value

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

15. Which of the following is not a valid method return type?


a. void
b. int
c. class
d. boolean

16. The keyword return is followed by


a. the data type of the method
b. the object name
c. a value or variable
d. the method name

17. You must provide a return type for


a. every method
b. every method that returns a value
c. constructor methods
d. every void method

18. All class definitions are examples of


a. static methods
b. procedural programming
c. object declarations
d. encapsulation

19. You send messages to an object using


a. the new operator
b. object.method() notation
c. input devices
d. reference variables

20. When you compile a program, method calls


a. are saved as source code
b. are replaced with machine code
c. are executed immediately
d. are ignored until runtime

Chapter 4: Review Questions

1. The symbols <, >, and == are examples of


a. arithmetic operators
b. Boolean operators
c. comparison operators
d. mathematical operators

2. The values compared in a decision are the


a. operands
b. operations
c. expressions
d. equations

3. In Java, the expression 7 != 5 evaluates to


a. true
b. false
c. 7
d. 5

4. The expression 5 >= 6 evaluates to


a. 5
b. 6
c. true
d. false

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

6. The lowest precedence in the Java programming language is held by


a. ==
b. &&
c. ||
d. <

7. The equal sign in a Boolean expression is actually


a. :=
b. ==
c. =
d. .eq.

8. If a > b and b > c, then


a. a < c
b. a > c
c. a == c
d. nothing is known about a and c

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

11. If the Boolean expression in an if-else statement is false, the program


a. executes the else block
b. skips the else block
c. skips both blocks
d. executes both blocks

12. Nested if statements are


a. illegal
b. hard-coded
c. multiple if statements contained within each other
d. compiled before execution
13. A decision structure in which you choose between three or more actions is
a. an if-else statement
b. a switch statement
c. a multiple decision
d. a loop

14. A switch statement must include


a. one case
b. a default
c. a controlling expression
d. break statements

15. A case in a switch structure must end with a


a. default
b. loop
c. break
d. return

16. If you omit the break statement in a switch structure


a. only the selected case executes
b. all cases execute
c. fall-through occurs
d. a compiler error results

17. The scope of a variable declared in a case block is


a. the entire switch
b. the individual case
c. the class
d. the method

18. A nested decision structure occurs when


a. multiple if statements are used
b. the default is used
c. a switch is inside an if
d. one decision is inside another

Chapter 5: Review Questions

1. A structure that allows repeated execution of a block of statements is a(n)


a. cycle
b. loop
c. ring
d. iteration
2. A loop that never ends is a(n)
a. infinite loop
b. invalid loop
c. conditional loop
d. terminated loop

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

5. In a while loop, the body executes


a. before the condition is checked
b. only if the condition is true
c. regardless of the condition
d. zero times only

6. A loop control variable is used to


a. initialize the class
b. access class fields
c. control the number of loop iterations
d. return a value from a method

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

8. The do...while loop always executes


a. once
b. at least once
c. twice
d. zero or more times

9. A for loop includes all the following except


a. initialization
b. condition
c. update
d. method call

10. In a for loop, the loop control variable is usually updated


a. manually inside the loop body
b. automatically at the end of the loop body
c. at the beginning of each iteration
d. in the update expression

11. A loop that is placed within another loop is a


a. concurrent loop
b. tandem loop
c. nested loop
d. series loop

12. In a nested loop, the inner loop


a. executes fewer times than the outer loop
b. executes one time for each outer loop iteration
c. executes independently of the outer loop
d. controls the outer loop

13. When a loop executes, the program control


a. always jumps back to the top of the method
b. may or may not return to the condition test
c. returns to the loop control expression
d. resets to the loop start

14. An off-by-one error occurs when


a. a loop executes one too many or one too few times
b. the loop counter is declared incorrectly
c. there are syntax errors in the loop
d. a condition is always false

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

18. Which of the following will cause a while loop to terminate?


a. A break statement
b. The condition becomes false
c. The loop variable is no longer valid
d. Any of the above

Chapter 6: Review Questions

1. A list of variables that are accessed with an index number is


a. a collection
b. an array
c. a data file
d. a record

2. Each individual variable in an array is known as a(n)


a. item
b. field
c. element
d. index

3. The index of the first element in an array is


a. 1
b. 0
c. -1
d. dependent on the array type

4. When you declare an array, you use


a. parentheses
b. curly braces
c. square brackets
d. angle brackets

5. An array declaration does not include


a. the data type
b. the size
c. an initializer
d. the identifier
6. When you instantiate an array, you use the keyword
a. instantiate
b. array
c. new
d. create

7. You can initialize an array when you declare it by


a. listing the values inside parentheses
b. listing the values in a method call
c. listing the values inside curly braces
d. using the array constructor

8. The length of an array is


a. the number of elements it can hold
b. always fixed
c. accessed with .length
d. all of the above

9. To process every element in an array, you use


a. a loop
b. a method
c. an assignment
d. a counter

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

11. A loop that visits every element in an array is called


a. a parallel loop
b. a full traversal
c. a total loop
d. a universal loop

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

13. The term “out of bounds” refers to


a. accessing an element outside the limits of the array
b. reassigning the length of the array
c. using undeclared arrays
d. using a two-dimensional array

14. Parallel arrays


a. are nested within each other
b. hold different types of related data
c. have elements that correspond by index
d. are illegal in Java

15. Arrays that hold other arrays are


a. compound arrays
b. multidimensional arrays
c. multiple arrays
d. reference arrays

16. When declaring a two-dimensional array, you use


a. two pairs of square brackets
b. nested loops
c. semicolons
d. commas

17. The value of an uninitialized element in a numeric array is


a. 1
b. null
c. 0
d. undefined

18. A String array can be initialized with


a. “ ”
b. null
c. a string literal
d. all of the above

Chapter 7 – Characters, Strings, and the StringBuffer

1. A sequence of characters enclosed within double quotation marks is a


a. symbolic string
b. literal string
c. prompt
d. command

2. To create a String object, you can use the keyword


a. object
b. create
c. char
d. new

3. A String variable name is a


a. reference
b. value
c. constant
d. literal

4. Objects that cannot be changed are


a. irrevocable
b. nonvolatile
c. immutable
d. stable

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()

8. If a String is declared as String aStr = new String("lima bean");, then


aStr.equals("Lima Bean"); is
a. true
b. false
c. illegal
d. unknown

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

12. The String class replace() method replaces


a. a String with a character
b. one String with another String
c. one character in a String with another character
d. every occurrence of a character in a String with another character

13. The toString() method converts any to a String


a. character
b. integer
c. float
d. all of the above

14. Joining Strings is called


a. chaining
b. joining
c. linking
d. concatenation

Chapter 8 – Arrays

1. An array is a list of data items that


a. all have the same type
b. all have different names
c. all are integers
d. all are null
2. Declaring an array and reserving memory for an array
a. are always done in the same statement
b. are two distinct processes
c. depends on the type of array
d. must not use the keyword new

3. You reserve memory locations for an array when you


a. declare the array name
b. use the keyword new
c. use the keyword mem
d. explicitly store values within the array elements

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

1. A major difference between AWT and Swing applets is


a. the AWT applet uses a content pane
b. they are executed using different Java commands
c. they are executed from within different HTML documents
d. the Swing applet imports from the .javax.swing package

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

4. The ___ is a String representing a font.


a. point size
b. style
c. leading
d. typeface

5. A JTextField is a Swing component


a. into which a user can type a single line of text data
b. into which a user can type multiple lines of text data
c. that automatically has focus when the applet runs
d. whose text cannot be changed

6. The Swing add() method


a. adds two integers
b. adds a component directly to the Swing applet
c. places a component within a container
d. places a text value within an applet component

7. The start() method called in any Swing applet is called


a. at start-up
b. when the user closes the browser
c. when a user revisits an applet
d. when a user leaves a Web page

8. A Font object contains all of the following arguments except


a. language
b. typeface
c. style
d. point size

9. To respond to user events within a Swing applet, you must


a. prepare the applet to accept event messages
b. import the java.applet.* package
c. tell your applet how to respond to any events that happen
d. accomplish both a and c

10. The constructor public JButton("4") creates


a. an unlabeled JButton
b. a JButton four pixels wide
c. a JButton four characters wide
d. a JButton with a “4” on it
11. An event occurs when a
a. component requests focus
b. component is enabled
c. component sets text
d. button is clicked

12. ActionListener is an example of a(n)


a. import
b. applet
c. interface
d. component

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");

16. Which of the following statements correctly creates a Font object?


a. Font aFont = new Font("TimesRoman", Font.ITALIC, 20);
b. Font aFont = new Font(30, "Helvetica", Font.ITALIC);
c. Font aFont = new Font(Font.BOLD,"Helvetica", 24);
d. Font aFont = new Font(22, Font.BOLD, "TimesRoman");

17. The method that positions a component within an applet is


a. position()
b. setPosition()
c. location()
d. setLocation()

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

1. The method that calls the paint() method for you is


a. callPaint()
b. repaint()
c. requestPaint()
d. draw()

2. The paint() method header requires a(n) ___ argument.


a. void
b. integer
c. String
d. Graphics

3. The statement g.drawString(someString, 50, 100); places someString’s corner at


position 50, 100.
a. upper-left
b. lower-left
c. upper-right
d. lower-right

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

5. The correct statement to instantiate a Graphics object named picasso is


a. Graphics picasso;
b. Graphics picasso = new Graphics();
c. Graphics picasso = getGraphics();
d. Graphics picasso = getGraphics(new);
6. The statement g.drawRoundRect(100,100,100,100,0,0); draws a shape that looks
most like a
a. square
b. round-edged rectangle
c. circle
d. straight line

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

9. The method you use to create a solid arc is


a. solidArc()
b. fillArc()
c. arcSolid()
d. arcFill()

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

14. The getScreenResolution() method and getScreenSize() method


a. both return the number of pixels as an int type
b. return the number of pixels as an int type and an object of type Dimension
c. both return an object of type Dimension
d. return the number of pixels as a double type and an object of type Dimension

15. A Graphics2D object is produced by


a. the setGraphics2D() method
b. the Graphics2D newpen = Graphics2D() statement
c. the Graphics2D = Graphics(g) statement
d. casting a Graphics object

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

17. A gradient fill is a gradual change in


a. color
b. font size
c. drawing style
d. line thickness

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

20. Showing successive images on the screen is called


a. action-oriented
b. object-oriented
c. animation
d. volatility

Chapter 11 – Introduction to Inheritance

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

2. Employing inheritance reduces errors because


a. the new classes have access to fewer data fields
b. the new classes have access to fewer methods
c. you can copy methods that you already created
d. many of the methods you need have already been used and tested

3. A base class can also be called a


a. child class
b. subclass
c. derived class
d. superclass

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

5. The Java keyword that creates inheritance is


a. static
b. enlarge
c. extends
d. inherits

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

7. Which of the following statements is false?


a. A child class inherits from a parent class
b. A parent class inherits from a child class
c. Both of the above statements are false
d. Neither of the above statements is false

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

11. If a superclass constructor requires arguments, then its subclass


a. must contain a constructor
b. must not contain a constructor
c. must contain a constructor that requires arguments
d. must not contain a constructor that requires arguments

12. If a superclass constructor requires arguments, any constructor of its subclasses


must call the superclass constructor
a. as the first statement
b. as the last statement
c. at some time
d. multiple times if multiple arguments are involved

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

16. Within a subclass, you cannot override ___ methods.


a. public
b. private
c. protected
d. constructor

17. You call a static method using a(n) ___ name.


a. class
b. superclass
c. object
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

19. A compiler can decide to ___ a final method.


a. duplicate
b. inline
c. redline
d. beeline

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

Chapter 12 – Advanced Inheritance Concepts

1. Parent classes are ___ than their child classes.


a. smaller
b. more specific
c. easier to understand
d. more cryptic

2. Abstract classes differ from regular classes in that you


a. must not code any methods within them
b. must instantiate objects from them
c. cannot instantiate objects from them
d. cannot have data fields within them

3. Abstract classes can contain


a. abstract methods
b. nonabstract methods
c. both of the above
d. none of the above

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

7. Which of the following statements are false?


a. Subclass objects are members of their superclass.
b. Superclass objects can contain abstract methods.
c. You can convert subclass objects to superclass objects.
d. Two of the above statements are false.

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

10. The statement Currency[] currencyRef = new Currency[5];


a. creates an array of five reference objects of an abstract class named Currency.
b. creates five concrete Currency objects
c. creates one Currency object
d. throws a compiler error

11. You ___ override the toString() method in any class you create.
a. cannot
b. can
c. must
d. must implement StringListener to

12. The Object class equals() method takes


a. no arguments
b. one argument
c. two arguments
d. as many arguments as needed

13. Given: if(thing.equals(anotherThing)) x = 1;, you know that


a. thing is an Object
b. anotherThing is the same type as thing
c. both a and b are correct
d. neither a nor b is correct
14. The equals() method considers two objects of the same class equal if they have the
same
a. value in all data fields
b. value in any data field
c. data type
d. memory address

15. Java subclasses have the ability to inherit from ___ parent class(es).
a. one
b. two
c. multiple
d. no

16. The alternative to multiple inheritance in Java is


a. a superobject
b. an abstract class
c. an interface
d. none of the above

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

18. You cannot instantiate concrete objects from a(n)


a. abstract class
b. interface
c. either a or b
d. neither a nor b

19. In Java, a class can


a. inherit from only one abstract superclass
b. implement only one interface
c. both a and b
d. neither a nor b

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

2. The File class enables you to


a. open a file
b. close a file
c. determine a file’s size
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

4. The statement File aFile = new File("myFile"); creates a file


a. on the disk in drive A
b. on the hard drive (drive C)
c. in the Temp folder on the hard drive (drive C)
d. on the default disk drive

5. The File method canWrite() returns a(n) ___ value.


a. int
b. Boolean
c. Object
d. void

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

7. A group of characters that has meaning is a


a. file
b. record
c. field
d. byte
8. Files consist of related
a. records
b. fields
c. data segments
d. archives

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

11. Most streams flow


a. in
b. out
c. either in or out, but only in one direction
d. both in and out concurrently

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

13. A small memory location that is used to temporarily hold data is a


a. stream
b. buffer
c. bulwark
d. channel

14. The read() method returns a value of -1 when it encounters a(n)


a. input error
b. integer
c. end-of-file condition
d. negative value

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

16. You use a DataOutputStream connected to FileOutputStream by using a method


known as
a. sequencing
b. iteration
c. piggybacking
d. chaining

17. When you catch an EOFException, it means you have


(Question cut off in the scan but likely refers to reaching the end of file.)

Chapter 14 – Using Layout Managers and the Event Model

1. If you add fewer than five components to a BorderLayout


a. any empty component regions disappear
b. the remaining components expand to fill the available space
c. both a and b
d. none of the above

2. When you resize a Container that uses BorderLayout,


a. the Container and the regions both change in size
b. the Container changes in size, but the regions retain their original sizes
c. the Container retains its size, but the regions change or might disappear
d. nothing happens

3. The statement setLayout(new BorderLayout()); is valid. Which of the following is


also valid?
a. myFrame.setLayout(new BorderLayout());
b. myFrame.setLayout(BorderLayout());
c. setLayout(myFrame = new BorderLayout());
d. setLayout(BorderLayout(myFrame));

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

7. The statement setLayout(new FlowLayout(FlowLayout.LEFT)); ensures that


components are placed left-to-right across the Swing applet surface until the first
row is full.
a. setLayout(FlowLayout.LEFT);
b. setLayout(new FlowLayout(LEFT));
c. setLayout(new FlowLayout(FlowLayout.LEFT));
d. setLayout(FlowLayout(FlowLayout.LEFT));

8. The GridBagLayout class allows you to


a. add components to precise locations within the grid
b. indicate that specific components should span multiple rows or columns within
the grid
c. both a and b
d. none of the above

9. The statement setLayout(new GridLayout(2,7)); establishes a GridLayout with how


many horizontal rows?
a. zero
b. one
c. two
d. seven

10. As you add new components to a GridLayout,


a. they are positioned left-to-right across each row in sequence
b. you can specify exact positions by skipping some positions
c. both of the above
d. none of the above

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

13. AWTEvent is the child class of


a. EventObject
b. Event
c. ComponentEvent
d. ItemEvent

14. When a user clicks a JPanel, the action generates a(n)


a. ActionEvent
b. MouseEvent
c. ButtonEvent
d. none of the above

15. Event handlers are


a. abstract classes
b. concrete classes
c. listeners
d. methods

16. The return type of getComponent() is


a. Object
b. Component
c. int
d. void

17. The KeyEvent method getKeyChar() returns a


a. int
b. char
c. KeyEvent
d. AWTEvent

18. The MouseEvent method that allows you to identify double-clicks is


a. getDouble()
b. isClickDouble()
c. getDoubleClick()
d. getClickCount()

19. You can use the ___ method to determine the Object where an ActionEvent
originates.
a. getObject()
b. getEvent()
c. getOrigin()
d. getSource()

20. The mousePressed() method is originally defined in the


a. MouseListener interface
b. MouseEvent event
c. MouseObject object
d. AWTEvent class

Chapter 15 – Exception Handling

1. In object-oriented programming terminology, an unexpected or error condition is


a(n)
a. anomaly
b. aberration
c. deviation
d. exception

2. All Java Exceptions are


a. Errors
b. RuntimeExceptions
c. Throwables
d. Omissions

3. Which of the following statements is true?


a. Exceptions are more serious than Errors.
b. Errors are more serious than Exceptions.
c. Errors and Exceptions are equally serious.
d. Exceptions and Errors are the same thing.

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()

5. In object-oriented terminology, you ___ a procedure that might not complete


correctly.
a. try
b. catch
c. handle
d. encapsulate
6. A method that detects an error condition or Exception ___ an Exception.
a. tries
b. catches
c. handles
d. encapsulates

7. A try block includes all of the following elements except


a. the keyword try
b. the keyword catch
c. curly braces
d. statements that might cause Exceptions

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

9. You ___ within a try block.


a. must place only a single statement
b. can place any number of statements
c. must place at least two statements
d. must place a catch block

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

14. An advantage to using a try...catch block is that exceptional events are


a. eliminated
b. reduced
c. integrated with regular events
d. isolated from regular events

15. Which methods can throw an Exception?


a. Methods with a throws clause
b. Methods with a catch block
c. Methods with both a throws clause and a catch block
d. Any method

16. A method can


a. check for errors but not handle them
b. handle errors but not check for them
c. either of the above
d. neither of the above

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

2. The File class enables you to


a. open a file
b. close a file
c. determine a file’s size
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

4. The statement File aFile = new File("myFile"); creates a file


a. on the disk in drive A
b. on the hard drive (drive C)
c. in the Temp folder on the hard drive (drive C)
d. on the default disk drive

5. The File method canWrite() returns a(n) ___ value.


a. int
b. Boolean
c. Object
d. void

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

7. A group of characters that has meaning is a


a. file
b. record
c. field
d. byte
8. Files consist of related
a. records
b. fields
c. data segments
d. archives

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

11. Most streams flow


a. in
b. out
c. either in or out, but only in one direction
d. both in and out concurrently

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

13. A small memory location that is used to temporarily hold data is a


a. stream
b. buffer
c. bulwark
d. channel

14. The read() method returns a value of -1 when it encounters a(n)


a. input error
b. integer
c. end-of-file condition
d. negative value

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

16. You use a DataOutputStream connected to FileOutputStream by using a method


known as
a. sequencing
b. iteration
c. piggybacking
d. chaining

17. When you catch an EOFException, it means you have


a. failed to find the end of the file
b. forgotten to open a file
c. forgotten to close a file
d. reached the end of a file

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()

20. You can open a RandomAccessFile object for


a. reading
b. writing
c. both of the above
d. none of the above

You might also like