Java Chapter 8
A source code file may contain several classes A. true B. false
A
A static data field can be accessed from any method in the same class A. true B. false
A
A static method in a class can access the class variables in the same class. A. true B. false
A
All data fields in an object have default values A. true B. false
A
Array variable are reference variables A. true B. false
A
Each class in the file is compiled into a separate bytecode file A. true B. false
A
Java assigns a default value to a data member of a class if the data is not initialized A. true B. false
A
Java uses _________ to reference the current object A. this B. null C. that D. thisObject
A
The default constructor has no arguments A. true B. false
A
The default value null is assigned to a data member of object type, even though the data member is not created yet. A. true B. false
A
Variables that are shared by every instances of a class are ___________. A. class variables B. instance variables C. private variables D. public variables
A
What is an advantage of encapsulation? A. it changes the implementation without changing a class's contract and causes no consequential changes to other code B. Only public methods are needed C. it changes a class's contract without changing the implementation and causes no consequential changes to other code D. Making the class final causes no consequential changes to other code
A
Which of the following can be placed in the blank line? public class Test { private int id; public void m1() { ___________.id = 45; } } A. this B. Test
A
You can access a class variable using a syntax like objectName.classVariable or ClassName.classVariable A. true B. false
A
You can declare a local variable in a method that has same name as an instance variable in the class A. true B. false
A
You can declare variables of the same name in a method if they are in non-nesting blocks A. true B. False
A
You cannot use modifiers on local variables inside a method except final. A. true B. false
A
You cannot use the private modifier on classes A. true B. false
A
You use the plus sign(+) to denote public data or methods A. true B. false
A
___________ represents an entity in the real world that can be distinctly identified A. An object B. A data field C. A method D. A class
A
Which of the following are properties of a constructor? A. Constructors may be overloaded B. A constructor is called using the new operator C. A constructor must have the same name as the class
A B C
A method that is associated with an individual object is called _________. A. a class method B. an instance method C. a static method D. an object method
B
A static method in a class can access the instance variables in the same class A. true B. false
B
All local variables in a method have default values A. true B. false
B
An object is an instance of a __________. A. program B. class C. method D. data
B
Given the declaration Circle x = new Circle(), which of the following statement is most accurate. A. x contains an object of the Circle type B. x contains a reference to a Circle object C. You can assign an int value to x D. x contains an int value
B
Java assigns a default value to a local variable in a method if the variable is not initialized A. true B. false
B
The default value for a data member of boolean type is true A. true B. false
B
The keyword __________ is required to declare a class A. public B. class C. private D. all of the above
B
To prevent a class from being instantiated, ________________. A. use the public modifier on the constructor B. use the private modifier on the constructor C. use the static modifier on the constructor D. don't use any modifiers on the constructor
B
You can always use the default constructor even though the non-default constructors are defined in the class A. true B. false
B
You can declare variables of the same name in a method even though they are in the same block A. True B. False
B
_____________ is invoked to create an object. A. The main method B. A constructor C. A method with a return type D. A method with the void return type
B
______________ can be accessed from any static method in the class A. A local variable B. A static variable C. An instance variable
B
Suppose the xMethod() is invoked from a main method in a class as follows, xMethod() is _________ in the class. public static void main(String[] args) { xMethod(); } A. an instance method B. a static method or an instance method C. a static method
C
Suppose the xMethod() is invoked in the following constructor in a class, xMethod() is _________ in the class. public MyClass() { xMethod(); } A. a static method B. an instance method C. a static method or an instance method
C
The default value for data field of a boolean type, numeric type, object type is _____________, respectively A. false, 1, null B. true, 1, null C. false, 0, null D. true, 0, null
C
___________ is a construct that defines objects of the same type A. a data field B. an object C. a class D. a method
C
How many JFrame objects can you create and how many can you display? A. one B. two C. three D unlimited
D
To declare a constant MAX_LENGTH as a member fo the class, you write _________. A. final static float MAX_LENGTH = 99.98 B. final double MAX_LENGTH = 99.98 C. static double MAX_LENGTH = 99.98 D. final static double MAX_LENGTH = 99.98
D
When invoking a method with an object argument, ___________ is passed. A. a copy of the object B. the contents of the object C. the object is copied, then the reference of the copied object D. the reference of the object
D
You can declare two variables with the same name in _________. A. two nested blocks in a method (one being inside of the other) B. a block C. a method one as a formal parameter and the other as a local variable D. different methods in a class
D
You use the ________ operator to access members of an object A. () B. % C. * D. .
D