Chapter 9

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

immutable class

a class is immutable if it contains all private data fields and no mutator methods and no accessor methods that would return a reference to a mutable data field object.

An object is an instance of a __________. A. program B. class C. method D. data

B

The default value for data field of a boolean type, numeric type, object type is ___________, respectively. A. true, 1, Null B. false, 0, null C. true, 0, null D. true, 1, null E. false, 1, null

B

How do you create an object?

The syntax to create an object is new ClassName();

instance

an object of a class

action

and action that can be called by an object

instantiation

the process of creating an object of a class

public class

the public visibility modifier is used for the class

What is NullPointerException?

A NullPointerException occurs when a null reference variable is used to access the members of an object.

__________ represents an entity in the real world that can be distinctly identified. A. A class B. An object C. A method D. A data field

B

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.

B and D

static variable

a data member declared using the static modifier. A static variable is shared by all instances of that class. Static variables are used to communicate between different objects of the same class and to handle global states among these objects.

reference type

a data type that is a class or an interface

Unified Modeling Language (UML)

a graphical notation for describing classes and their relationships

static method

a method that can be invoked without creating an instance of the class. To define static methods, put the modifier static in the method declaration.

instance variable

a nonstatic data member of a class. An instance variable belongs to an instance of the class.

instance method

a nonstatic method in a class. Instance methods belong to instances and can only be invoked by them.

private constuctor

a private constructor prevents constructing objects from the class

constuctor

a special method for initializing objects when creating objects using the new operator. The constructor has exactly the same name as its defining class. Constructors can be overloaded, making it easier to construct objects with different initial data values.

reference variable

a variable of a class type

attribute

a variable that stores a value for an object

class

an encapsulated collection of data and methods that operate on data. A class may be instantiated to create an object that is an instance of the class.

immutable object

an object of immutable class

anonymous object

an object without being assigned to a reference variable.

dot operator

an operator used to access members of an object. If the member is static, it can be accessed through the class name using the dot operator.

default constructor

if a class does not define any constructors explicitly, a no-argument constructor with empty body is assumed.

package-private (or package-access)

if public or private is not used, then by default the classes, methods, and data are accessible by any class in the same package.

setter

is a method for changing a property value

getter

is a method for returning a property value

client

refers the program that uses a class. The program is known as a client of the class.

keyword

refers to the object itself

class's variable

refers to the variable defined in the class

behavior

same as action

data field

same as attribute

property

same as attribute

accessor

same as getter

mutator

same as setter

State

the state of an object is described by attributes of the object.

data field encapsulation

to prevent direct modifications of properties through the object reference, you can declare the field private, using the private modifier.Data field encapsulation makes the class easy to maintain.

Constructors are a special kind of method. They have three peculiarities:

1.) A constructor must have the same name as the class itself. 2.) Constructors do not have a return type—not even void. 3.) Constructors are invoked using the new operator when an object is created. Constructors play the role of initializing objects.

_______ is a template that defines objects of the same type. A. A class B. An object C. A method D. A data field

A

The keyword __________ is required to define a class. A. static B. void C. class D. int

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

Write a statement to declare a variable named x for an object type Circle.

Circle x;

Write a statement that declares a variable of the Circle type named x and assign it with a Circle object of radius 5.5.

Circle x= new Circle(5.5);

What are the differences between constructors and methods?

Constructors are special kinds of methods that are called when creating an object using the new operator. Constructors do not have a return type-not even void.

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

D

no-argument constructor

a constructor without arguments

Write an expression that returns the area of a Circle object c by invoking its getArea() method.

c.getArea()

Write an expression for creating a Circle object using its no-arg constructor.

new Circle()


Ensembles d'études connexes

Fundamentals of Nursing CH4: Safety

View Set

D101 Cost & Managerial Accounting Module 3

View Set

#1-5F. Digital Transformation [Part C] - Finance - (Innovation Strategy: Developing Your Fintech strategy).

View Set

Module 11 E-mail and Social Media Investigations

View Set

PrepU #3 Parkinsons, MS, and Sz Quiz

View Set

Chapter 8 Anatomy and Physiology

View Set