Intro to Java Programming Chapter 3
The access specifier in the declaration of instance variables should be ___. A. class B. protected C. private D. public
private
Instance variables that are numbers are initialized to what default value? A. 0 B. nil C. Instance variables are not initialized to a default value. D. null
0
What will be output from the following statements that use BankAccount class? BankAccount first = new BankAccount (100); BankAccount second = new BankAccount (100); BankAccount third = first; first.deposit (50.0); second.deposit (50.0); third.deposit (50.0); System.out.println (first.getBalance() + " " + second.getBalance() + third.getBalance()); A. 200.0 150.0 200.0 B. 250.0 250.0 250.0 C. 150.0 150.0 150.0 D. 150.0 200.0 250.0
200.0 150.0 200.0
What is the return type of a constructor? A. private B. public C. A constructor does not have a return type. D. void
A constructor does not have a return type.
What is a local variable? A. A variable that is declared in the body of the class. B. A variable that is declared in the header of a method. C. A variable that is declared in the body of a method. D. A variable that is declared in the header of a class.
A variable that is declared in the body of a method.
What is a parameter variable? A. A variable that is declared in the header of a class. B. A variable that is declared in the body of the class. C. A variable that is declared in the header of a method. D. A variable that is declared in the body of a method.
A variable that is declared in the header of a method.
Why is it a good idea for a programmer to write comments about a method first, before implementing it? A. It can help to assign good variable names. B. It is a good idea for complex methods, but not simple ones. C. It is an excellent test to ensure that the programmer firmly understands what is needed. D. Without comments it is not possible to compile the code.
It is an excellent test to ensure that the programmer firmly understands what is needed.
When are local variables initialized? A. You must initialize local variables in the constructor. B. You must initialize local variables in a method body. C. Local variables are initialized when the method is called. D. Local variables are initialized with a default value before a constructor is invoked.
You must initialize local variables in a method body.
A method header consists of which of the following parts? A. the return type, the name of the method, and a list of the parameters (if any) B. the type of the instance variable, an access specifier, and a list of the parameters (if any) C. an access specifier, the type of the instance variable, and the name of the instance variable D. an access specifier, a return type, a method name, and a list of the parameters (if any)
an access specifier, a return type, a method name, and a list of the parameters (if any)
A class declaration consists of which of the following parts? A. an access specifier, the keyword class, the name of the class, declarations for instance variables, constructors, and methods B. an access specifier, the name of the class, a list of the parameters (if any), and the body of the constructor C. an access specifier, a return type, a method name, a list of the parameters (if any), and the body of the method D. the name of the class, declarations for instance variables, constructors, and methods
an access specifier, the keyword class, the name of the class, declarations for instance variables, constructors, and methods
An instance variable declaration consists of which of the following parts? A. the return type, the name of the method, and a list of the parameters (if any). B. the type of the instance variable, an access specifier, a list of the parameters (if any), and the body of the method. C. an access specifier, the type of the instance variable, and the name of the instance variable. D. an access specifier, a list of the parameters (if any), and the body of the method.
an access specifier, the type of the instance variable, and the name of the instance variable.
The class constructor always has the same name as __. A. instance variable B. parameter variable C. access specifier D. class
class
Which part of a class implementation contains the instructions to initialize an object's instance variables? A. initializer B. constructor C. type name D. access specifier
constructor
You should provide documentation comments for ___ A. every class, every method, every parameter, and every return value B. only methods with parameters C. only classes D. only methods with return values
every class, every method, every parameter, and every return value
Encapsulation allows a programmer to use a class without having to know its ____. A. interface B. implementation C. methods D. name
implementation
Each object of a class has its own set of ___. A. methods B. instance variables C. constructors D. classes
instance variables
The public constructors and methods of a class form the public _____ of the class. A. initialization B. encapsulation C. implementation D. interface
interface
When a method exits, its ____ are removed. A. local variables B. comments C. classes D. instance variables
local variables
Which line of code is part of the public implementation of the BankAccount class? A. balance = balance - amount; B. public BankAccount(double initialBalance) C. balance = balance + amount; D. return balance;
public BankAccount(double initialBalance)
What verifies that a class works correctly in isolation, outside a complete program? A. abstraction B. unit test C. enumeration D. encapsulation
unit test