Chapter 3: Implementing Classes Flashcards

1
Q

Where does an object store its data?

A

an instance variable

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

What is an instance of a class?

A

an object of the class

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

What are the 3 parts that an instance variable declaration consist of?

A

1.) an access specifier (private)
2.) The type of the instance variable
3.) The name of the instance variable

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

Write a code for the click method, which advances the counter value by 1

A

public void click()
{
value = value + 1
}

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

Write the getValue method

A

public int getValue()
{
return value;
}

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

T/F: Private instance values can only be accessed by methods of the same class.

A

True

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

What is encapsulation?

A

the process of hiding implementation details and providing methods for data access

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

What does encapsulation allow a programmer to do?

A

use a class without having to know its implementation

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

What does information hiding make it easier to do?

A

locate errors and change implementation

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

What do you need to know before implementing a class

A

which methods are required

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

What do constructors do?

A

set the initial data for objects

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

What is the name of a constructor?

A

the name of the class

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

What are constructors return type?

A

trick question: constructors have no return type (not even void)

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

What is the name for a constructor that takes no argument

A

a no-argument constructor

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

What is the following an example of?
public BankAccount()

A

a no-argument constructor

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

Where do you place constructors and method declarations?

A

inside a class

17
Q

What are documentation comments used for?

A

to describe the classes and public methods of your program

18
Q

What is the @param tag used for

A

methods with no arguments

19
Q

What is the @return tag used for

A

methods whose return type is void

20
Q

What does the private implementation of a class consist of?

A

instance variables and the bodies of constructors and methods

21
Q

What is the simple job of a constructor?

A

to initialize the instance variables of an object

22
Q

What does a unit test do?

A

verify that a class works in isolation

23
Q

What are the two ways to test a class?

A

use an environment for interactive testing, or write a tester class to execute test instructions

24
Q

What is a local variable?

A

a variable that is declared in the body of a method

25
Q

Where are parameter variables declared?

A

in the method header

26
Q

What happens when a method exits?

A

its local variables are removed

27
Q

Where do instance variables belong to?

A

objects (not methods)

28
Q

T/F: You must initialize local variables

A

True

29
Q

T/F: You must initialize instance variables

A

False

30
Q

What is the implicit parameter?

A

the use of the instance variable in a method

31
Q

What reference denotes the implicit parameter?

A

this

32
Q

T/F: An instance variable shadows a local variable with the same name

A

False - a local variable shadows an instance variable with the same name.

33
Q
A