Chapter 9: Objects and Classes Flashcards

1
Q

What is an object and what is its function?

A

An object represents something that exists in real life inside the program. The state of an object is defined by its data fields (A circle is defined by its radius). The behavior of the object is defined by methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a class and what is its function?

A

A class is a design plan for an object. A class can declare what data fields and methods an object has. An object is an instance of a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do classes and objects connect?

A

An object is an instance of a class. A class is a definition and an object is one example that fits inside that definition. The relationship is analogous. A class would be an apple-pie recipe, while each individual apple pie is one object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you use a constructor(s)?

A

A constructor is what is used to create (construct haha) a new instance of an object. They are designed to initialize, such as initializing the data fields. They must have the same name as the class, have no return type, and use the “new” operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between instance and static?

A

An instance refers to a single object within a class that can have a unique value. A static is a variable shared by all objects within a class and can’t access instance members. A final static is a variable that can’t be changed such as the value of PI (3.14….)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a reference type and how does it relate to classes?

A

A class is a reference type. A variable of the class type can reference an instance (object) of the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is an object reference variable?

A

Strictly speaking, an object reference variable and an object are different, but most of the time the distinction can be ignored. Therefore, it is fine, for simplicity, to say that myCircle is a Circle object rather than use the long-winded description that myCircle is a variable that contains a reference to a Circle object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you access an Object’s Data and Methods?

A

Using the dot(.) operator

objectRefVar.dataField = myCricle.radius

objectRefVar.method(arguments) = myCricle.getArea()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the null value?

A

If a data field of a reference type does not reference any object, the data field holds a special Java value, null. null is a literal just like true and false. While true and false are Boolean literals, null is a literal for a reference type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is data field encapsulation?

A

Declaring data fields private in order to protect those data fields from bugs and accidental changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is data field encapsulation?

A

Declaring data fields private in order to protect those data fields from bugs and accidental changes.

SIDE NOTE:
From now on, all data fields should be declared private, and all constructors and methods should be defined public, unless specified otherwise.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an immutable object and class?

A

An instance (object) of a class that once created, can’t be changed. For a class to be immutable it must have all private data fields, no mutator methods, and No accessor methods can return a reference to a data field that is mutable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly