Chapter 4 - Methods use instance variables Flashcards

1
Q

Point of an object

A

Has behavior that acts on it’s state

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

Methods use

A

Instance variable values

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

A method uses

A

Parameters

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

A caller passes

A

Arguments

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

What do you have to do if a method takes a parameter

A

You must pass it a value of the appropriate type

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

Arguments are

A

The things you pass into methods

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

A parameter is nothing more than

A

A local variable with a type and a name that can be used inside the body of the method

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

An example of an argument

A

d.bark(3); <— 3

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

An example of a parameter

A

void bark (int numOfBarks) <—numOfBarks

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

What does void mean?

A

Methods do not return anything back

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

Can methods have multiple parameters?

A

Yes. t.takeTwo(12, 34);

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

Java is?

A

Pass-by-value

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

What does pass-by-value mean

A

Pass-by-copy

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

Call the go()method, passing the variable x as the argument

A

foo.go(x);

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

Value means?

A

bits inside the variable. A variable is a reference to an object.

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

A method must

A

Declare a return type

17
Q

What is the purpose of a getter

A

To send back, as a return value, the value of whatever it is that particular Getter is supposed to be Getting

18
Q

What is the purpose of a setter

A

To take an argument value and use it to SET the value of an instance variable

19
Q

How do you hide data

A

With the public and private access modifiers

20
Q

An encapsulation starter rule of thumb

A

Mark your instance variables PRIVATE

Provide PUBLIC getters and setters for access control

21
Q

Declare and create a Dog array to hold 7 Dog references

A

Dog [] pets;

pets = new Dog [7];

22
Q

Instance variables always get a

A
Default value.  
Booleans -- Flase
References -- Null
Ints -- 0
Floats -- 0.0
23
Q

Why don’t you have to initialize instance variables

A

Because they always have a default value

24
Q

What is the default value for a reference variable

A

null

25
Q

The difference between instance and local vairables

A
  1. Instance variables are declared inside a class but not within a method
  2. Local variables are declared within a method
  3. Local variables MUST be initialized before use
26
Q

Do local variables get a default value

A

No.

27
Q

What do you need to determine if two objects are equal

A

The .equals()method

28
Q

The == is used only to compare?

A

The Bits in two variables

29
Q

When do you use ==

A

To compare two primitives, or to see if two references refer to the same object

30
Q

When do you use the equals method

A

To see if two different objects are equal

31
Q

A method uses …..

A

Parameters

32
Q

A caller passes

A

Arguments