Week_2 Flashcards

1
Q

What is the essential class structure in Java?

A

public class ClassName {
Constants
Instance Variables
Constructors
Accessors and Mutators
Behaviours (Methods)

toString()
}

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

What is an instance variable?

A

Instance variables describe the STATE of an object; they are declared at the TOP of a class; they are initialized IN a constructor.

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

What is encapsulation?

A

It is the bundling of data and the methods (behaviours) that work on that data.

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

What is information hiding?

A

We hide HOW methods achieve their results, and instead share only that information users need to know to achieve their goals

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

What are visibility modifiers?

A

Determine what is public (accessed by other classes) and what is private (can be referenced only within the class itself).

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

In a class, what should be public? What should be private?

A

Instance variables = PUBLIC

classes and constructors = PUBLIC

Methods part of interface = PUBLIC

Methods part of implementation = PRIVATE

Constants = public or private

Local variables – implicitly private; this doesn’t have to be explicitly declared.

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

What are getters / accessors?

A

They allow us to see an object’s data when its instance variables are all private; it gives us a copy of that object’s specific variables.

public int getPrice() {
return price; // return
}

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

What are setters / mutators?

A

Allow us to modify the data of a particular object.

public void setName (String newName) {
this.name = newName; // assignment
}

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

What are side effects?

A

A side-effect is an observable, permanent change that happens IN ADDITION TO the primary job of a method. Ideally, all methods should have one and only one job; they should NOT have side-effects.

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

What are four examples of side-effects?

A

1) Modifying a non-local variable.
2) Modifying a static variable.
3) Modifying a mutable argument passed to the method.
4) Performing IO, such as printing.

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

What is the .toString() method?

A

For developers, not users; it describes the current state of the object. It’s used whenever we use System.out.pringln() on the object.

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

What is the THIS keyword and how is it used?

A

THIS refers to the object whose methods is executing.

We use THIS to invoke an alternate constructor.

We use THIS when an instance variable and parameter have the same name. (THIS will refer specifically to the instance variable.)

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

What is coupling?

A

Coupling refers to the amount of reliance that modules have on each other. We aim for MINIMAL COUPLING.

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