CSCI 101 Chap 9: OOP Intro

¡Supera tus tareas y exámenes ahora con Quizwiz!

Constructor

is a method invoked to create a class; must have same name as a class and do not have a return type

Class Variables

Variables that are shared by every instances of a class are __________.

keyword: class

the keyword ___ is required to declare a class

Class

a construct that defines objects of the same type

Default constructor

a constructor with no parameters or body; given in a class without with defined constructors

Null

A literal for reference type; If a data field of reference type does not reference any object, then it as a ____ value

NullPointerException

A common runtime error that occurs when you invoke a method on a reference variable with a value of null

(an instance of...) a Class

An object is an instance of...

Anonymous Object

An object that is created but not given a name or reference

B and C

Assume java.util.Date[] dates = new java.util.Date[10], which of the following statements are true? A. dates is null. B. dates[0] is null. C. dates = new java.util.Date[5] is fine, which assigns a new array to dates. D. dates = new Date() is fine, which creates a new Date object and assigns to dates.

C

Given the declaration Circle x = new Circle(), which of the following statement is most accurate. A. x contains an int value. B. x contains an object of the Circle type. C. x contains a reference to a Circle object. D. You can assign an int value to x.

C

Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate? A. x contains an array of ten int values. B. x contains an array of ten objects of the Circle type. C. x contains a reference to an array and each element in the array can hold a reference to a Circle object. D. x contains a reference to an array and each element in the array can hold a Circle object.

false, 0, null

The default value for data field of a boolean type, numeric type, object type is ___________, respectively.

C

To prevent a class from being instantiated, _____________________ A. don't use any modifiers on the constructor. B. use the public modifier on the constructor. C. use the private modifier on the constructor. D. use the static modifier on the constructor.

C

When invoking a method with an object argument, ___________ is passed. A. the contents of the object B. a copy of the object C. the reference of the object D. the object is copied, then the reference of the copied object

C

Which is the advantage of encapsulation? A. Only public methods are needed. B. Making the class final causes no consequential changes to other code. C. It changes the implementation without changing a class's contract and causes no consequential changes to other code. D. It changes a class's contract without changing the implementation and causes no consequential changes to other code.

B and D

Which of the following statements are correct? A. A reference variable is an object. B. A reference variable references to an object. C. A data field in a class must be of a primitive type. D. A data field in a class can be of an object type.

All are Correct

Which of the following statements are correct? A. When creating a Random object, you have to specify the seed or use the default seed. B. If two Random objects have the same seed, the sequence of the random numbers obtained from these two objects are identical. C. The nextInt() method in the Random class returns the next random int value. D. The nextDouble() method in the Random class returns the next random double value.

A, B, D, and E

Which of the following statements are true about an immutable object? A. The contents of an immutable object cannot be modified. B. All properties of an immutable object must be private. C. All properties of an immutable object must be of primitive types. D. An object type property in an immutable object must also be immutable. E. An immutable object contains no mutator methods.

A and D

Which of the following statements are true? A. A default constructor is provided automatically if no constructors are explicitly declared in the class. B. At least one constructor must always be defined explicitly. C. Every class has a default constructor. D. The default constructor is a no-arg constructor.

A, B, C, and D

Which of the following statements are true? A. Local variables do not have default values. B. Data fields have default values. C. A variable of a primitive type holds a value of the primitive type. D. A variable of a reference type holds a reference to where an object is stored in the memory. E. You may assign an int value to a reference variable.

A, B, C, and D

Which of the following statements are true? A. Multiple constructors can be defined in a class. B. Constructors do not have a return type, not even void. C. Constructors must have the same name as the class itself. D. Constructors are invoked using the new operator when an object is created.

A, B, and D

Which of the following statements are true? A. Use the private modifier to encapsulate data fields. B. Encapsulating data fields makes the program easy to maintain. C. Encapsulating data fields makes the program short. D. Encapsulating data fields helps prevent programming errors.

D

You can declare two variables with the same name in __________. A. a method one as a formal parameter and the other as a local variable B. a block C. two nested blocks in a method (two nested blocks means one being inside the other) D. different methods in a class

Object

represents an entity in the real world that can be distinctly identified


Conjuntos de estudio relacionados

DHS Hazard Communication Standard

View Set

Principles of Real Estate II (Chapter 2 Vocabulary)

View Set

Tetracyclines, Aminoglycosides, & Others

View Set

Human Anatomy, CH 1, Test Prep Questions

View Set

Chapter 40 Corporate Directors, Officers and Shareholders

View Set