Programming Languages Chapter 03 Classes often provide public methods to allow 

subject Type Homework Help
subject Pages 9
subject Words 68
subject Authors Harvey Deitel, Paul Deitel

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Java How to Program, 10/e Multiple Choice Test Bank 1 of 11
Chapter 3 Introduction to Classes and Objects
3.2 Q1: Each class you create becomes a new ________ that can be used to declare variables and create objects.
a. package
b. instance
c. library
d. type.
3.2 Q2: You can declare new classes as needed; this is one reason Java is known as a(n) ________ language.
a. portable
b. incremental
c. extensible
d. virtual
3.2.1 Q1: Which of the following statements is false?
a. Each class declaration that begins with the access modifier private must be stored in a file that has the same
name as the class and ends with the .java filename extension.
b. Every class declaration contains keyword class followed immediately by the class’s name.
c. Class, method and variable names are identifiers.
d. An object has attributes that are implemented as instance variables and carried with it throughout its lifetime.
3.2.1 Q2: Which of the following statements is false?
a. By convention class names begin with an uppercase letter, and method and variable names begin with a
lowercase letter.
b. Instance variables exist before methods are called on an object, while the methods are executing and after the
methods complete execution.
c. A class normally contains one or more methods that manipulate the instance variables that belong to particular
objects of the class.
d. Instance variables can be declared anywhere inside a class.
3.2.1 Q3: Which of the following statements is true?
a. Each object (instance) of the class shares the class’s instance variables.
b. Most instance-variable declarations are preceded with the keyword public, which is an access modifier.
c. Variables or methods declared with access modifier private are accessible only to methods of the class in
which they’re declared.
d. None of the above is true.
3.2.1 Q4: When a method terminates, the values of its local variables are ________.
a. saved
page-pf2
Java How to Program, 10/e Multiple Choice Test Bank 2 of 11
d. lost
3.2.1 Q5: Which of the following statements is false?
a. Variables declared in the body of a particular method are local variables and can be used only in that method.
b. A method’s parameters are local variables of the method.
c. Every method’s body is delimited by left and right braces ({ and }).
d. Keyword null indicates that a method will perform a task but will not return any information.
3.2.1 Q6: Which of the following statements is false?
a. The method’s return type specifies the type of data returned to a method’s caller.
b. Empty parentheses following a method name indicate that the method does not require any parameters to
perform its task.
c. When a method that specifies a return type other than void is called and completes its task, the method must
return a result to its calling method
d. Classes often provide public methods to allow the class’s clients to set or get private instance variables; the
names of these methods must begin with set or get.
3.2.2 Q1: A class that creates an object of another class, then calls the object’s methods, is called a(n) ________
class.
a. object-oriented
b. inherited
c. caller
d. driver.
3.2.2 Q2: Which of the following statements is false?
a. Scanner method next reads characters until any white-space character is encountered, then returns the
characters as a String.
b. To call a method of an object, follow the object name with a comma, the method name and a set of parentheses
containing the method’s arguments.
c. A class instance creation expression begins with keyword new and creates a new object.
d. A constructor is similar to a method but is called implicitly by the new operator to initialize an object’s instance
variables at the time the object is created.
3.2.2 Q3: Which of the following statements is true?
a. Local variables are automatically initialized.
b. Every instance variable has a default initial valuea value provided by Java when you do not specify the
instance variable’s initial value.
c. The default value for an instance variable of type String is void.
d. The argument types in the method call must be identical to the types of the corresponding parameters in the
page-pf3
3.2.3 Q1: Which of the following statements is false?
a. The javac command can compile multiple classes at once; simply list the source-code filenames after the
command with each filename separated by a comma from the next.
b. If the directory containing the app includes only one app’s files, you can compile all of its classes with the
command javac *.java.
c. The asterisk (*) in javac *.java indicates that all files in the current directory ending with the filename
extension “.java” should be compiled.
d. All of the above are true.
3.2.4 Q1: Which of the following statements is false?
a. In the UML, each class is modeled in a class diagram as a rectangle with three compartments. The top one
contains the class’s name centered horizontally in boldface. The middle one contains the class’s attributes,
which correspond to instance variables in Java. The bottom one contains the class’s operations, which
correspond to methods and constructors in Java.
b. UML represents instance variables as an attribute name, followed by a colon and the type.
c. Private attributes are preceded by the keyword private in the UML.
d. The UML models operations by listing the operation name followed by a set of parentheses. A plus sign (+) in
front of the operation name indicates that the operation is a public.
3.2.4 Q2: Which of the following statements is true?
a. The UML models a parameter of an operation by listing the parameter name, followed by a colon and the
parameter value between the parentheses after the operation name.
b. The UML indicates an operation’s return type by placing a colon and the return value after the parentheses
following the operation name.
c. UML class diagrams do not specify return types for operations that do not return values.
d. Declaring instance variables public is known as data hiding or information hiding.
3.2.5 Q1: You must call most methods other than ________ explicitly to tell them to perform their tasks.
a. public methods
b. main
c. static methods
d. private methods
3.2.5 Q2: A key part of enabling the JVM to locate and call method main to begin the app’s execution is the
________ keyword, which indicates that main can be called without first creating an object of the class in which the
method is declared.
a. stable
b. private
c. static
d. public
3.2.5 Q3: Which of the following statements is false?
a. Most classes you’ll use in Java programs must be imported explicitly.
page-pf4
Java How to Program, 10/e Multiple Choice Test Bank 4 of 11
b. There’s a special relationship between classes that are compiled in the same directory. By default, such classes
are considered to be in the same packageknown as the default package.
c. Classes in the same package are implicitly imported into main.
d. An import declaration is not required when one class in a package uses another in the same package.
3.2.5 Q4: An import declaration is not required if you always refer to a class with its ________ name, which
includes its package name and class name.
a. compile-time
b. default package
c. paired
d. fully qualified name
3.2.6 Q1: Declaring instance variables ________ is known as data hiding or information hiding.
a. secure
b. private
c. static
d. masked
3.3 Q1: Types in Java are divided into two categories. The primitive types are boolean, byte, char, short, int,
long, float and double. All other types are ________ types.
a. static
b. reference
c. declared
d. source
3.3 Q2: Which of the following statements is false?
a. A primitive-type variable can store exactly one value of its declared type at a time.
b. Primitive-type instance variables are initialized by default.
c. Variables of types byte, char, short, int, long, float and double are initialized to 0.
d. Variables of type boolean are initialized to true.
3.3 Q3: Reference-type variables (called references) store ________ in memory.
a. the value of an object
b. a copy of an object
c. the location of an object
d. the size of an object
3.3 Q4: Which of the following statements is false?
a. A reference to an object is required to invoke an object’s methods.
b. A primitive-type variable does not refer to an object.
c. Reference-type instance variables are initialized by default to the value void.
d. A primitive-type variable cannot be used to invoke a method.
page-pf5
3.4 Q1: Java requires a ________ call for every object that’s created.
a. constructor
b. destructor
c. parameterless
d. parameterized
3.4.1 Q1: Which of the following statements is true?
a. Constructors can specify parameters and return types.
b. Constructors can specify parameters but not return types.
c. Constructors cannot specify parameters but can specify return types.
d. Constructors can specify neither parameters nor return types.
3.4.2 Q1: If a class does not define constructors, the compiler provides a default constructor with no parameters, and
the class’s instance variables are initialized to ________.
a. zero
b. null
c. their default values.
d. false
3.4.2 Q2: Which of the following statements is false?
a. If a class does not define constructors, the compiler provides a default constructor with no parameters.
b. If you declare a constructor for a class, the compiler will not create a default constructor for that class.
c. The UML models constructors in the third compartment of a class diagram.
d. To distinguish a constructor from a class’s operations, the UML places the word “constructor” between double
quotes before the constructor’s name.
3.5 Q1: Which of the following statements is false?
a. A floating-point number is a number with a decimal point.
b. Java provides two primitive types for storing floating-point numbers in memoryfloat and double.
c. Variables of type float represent single-precision floating-point numbers and have seven significant digits.
d. Variables of type double represent double-precision floating-point numbers; these require twice as much
memory as float variables and provide 14 significant digits.
3.5 Q2: Floating-point literals are of type ________ by default.
a. float
b. double
c. real
page-pf6
Java How to Program, 10/e Multiple Choice Test Bank 6 of 11
d. decimal
3.5.1 Q1: A __________ of a class called myClass is another class whose methods call the methods of myClass.
a. consumer
b. servant
c. caller
d. client
3.5.2 Q1: The format specifier ________ is used to output values of type float or double.
a. %f
b. %d
c. %fd
d. %r
3.5.2 Q2: The format specifier %.2f specifies that two digits of precision should be output ________ in the floating-
point number.
a. to the left of the decimal point
b. centered
c. to the right of the decimal point
d. None of the above.
3.6 Q1: Which class provides prebuilt dialog boxes that enable programs to display windows containing messages
(such windows are called message dialogs)?
a. JDialogBox.
b. JPrebuiltDialog.
c. JMessageDialog.
d. JOptionPane.
3.6 Q2: Which of the following statements is false?
a. You must create an object of class JOptionPane to use its static method showMessageDialog.
b. JOptionPane method showInputDialog displays an input dialog containing a prompt and a field (known as a text
field) in which a user can enter text.
c. String method format works like method System.out.printf, except that format returns the formatted String
rather than displaying it in a command window.
d. An input dialog allows the user to enter data into a program.
page-pf7
3.4 Q1: Attributes of a class are also known as:
e. Constructors.
f. Local variables.
g. Fields.
h. Classes.
3.4 Q2: What is the default initial value of a String instance variable?
e. ""
f. "default"
g. default
h. null
3.4 Q3: What type of methods allow a client of a class to assign values to a private instance variable?
a. Get methods.
b. Replace methods.
c. Assign methods.
d. Set methods.
3.5 Q1: What is the default value of a reference?
a. 0.
b. "".
c. null.
d. default.
3.6 Q1: A default constructor has how many parameters?
a. 0.
b. 1.
c. 2.
d. a variable number.
page-pf8
3.7 Q1: Which two Java primitive types store floating-point numbers?
a. decimal and float.
b. point and double.
c. float and double.
d. decimal and point.
3.7 Q2: What is the difference between a float and a double?
a. double variables store integers and float variables store floating-point numbers.
b. double variables store numbers with smaller magnitude and coarser detail.
c. double variables store numbers with larger magnitude and finer detail.
d. None of the above.
3.7 Q3: How many significant digits does a double variable have?
a. 7.
b. 8.
c. 14.
d. 15.
3.8 Q1: Which class provides prebuilt dialog boxes that enable programs to display windows containing messages
(such windows are called message dialogs)?
a. JDialogBox.
b. JPrebuiltDialog.
c. JMessageDialog.
d. JOptionPane.
3.8 Q2: Which class provides prebuilt dialog boxes that enable programs to display windows containing messages
(such windows are called message dialogs)?
a. JDialogBox.
b. JPrebuiltDialog.
c. JMessageDialog.
d. JOptionPane.
3.8 Q3: Which of the following statements is false?
a. You must create an object of class JOptionPane to use its static method showMessageDialog.
b. JOptionPane method showInputDialog displays an input dialog containing a prompt and a field (known as a text
field) in which a user can enter text.
c. String method format works like method System.out.printf, except that format returns the formatted String
rather than displaying it in a command window.
page-pf9
Java How to Program, 10/e Multiple Choice Test Bank 9 of 11
d. An input dialog allows the user to enter data into a program.
page-pfa
3.2 Q1: Every Java application is composed of at least one:
a. local variable
b. instance variable
c. public class declaration
d. imported class
3.2 Q2: A class instance creation expression contains:
a. Parentheses.
b. The new keyword.
c. The name of the class.
d. All of the above.
3.2 Q3: Calling a method of another object requires which item?
a. The dot separator.
b. Open and close braces.
c. The new keyword.
3.3 Q1: What is the name of the values the method call passes to the method for the parameters?
a. Arguments.
b. References.
c. Objects.
d. Values.
3.3 Q2: Which of the following is a Scanner method?
a. nextLine.
b. nextText.
c. nextWord.
d. readNext.
3.3 Q3: Multiple parameters are separated with what symbol?
a. Dot separator
b. Comma.
c. Parentheses.
d. Braces.
3.3 Q4: Which of the following is a valid fully qualified name?
a. Scanner.
b. java.Scanner.
page-pfb
Java How to Program, 10/e Multiple Choice Test Bank 11 of 11
c. util.Scanner.
d. java.util.Scanner.

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.