Week 2 Objects Flashcards

1
Q

What do objects allow us to do?

A

Bring together variables and methods into a single thing

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

What is the science of Java programming?

A

rules and syntax for making objects

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

What is the art of Java programming?

A

Which variables and methods to bring together

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

Scanner object - describe it

A

Has its own internal variable - stores it

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

What is encapsulation?

A

use an object without understanding the underlying code

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

What is java swing?

A

a package that helps you make a window

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

Generally, what does a class have?

A
  • a name (starting with a capital letter)
  • some variables (class atttributes that belong to the class)
  • some methods
  • a constructor method that allows you to create a new object
  • each class defined in its own file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does public mean?

A

it is a modifier that describes to which other objects they are visible.

All classes, class attributes and class methods have a modifier

public is visible by anything

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

What does private mean?

A

these classes, attributes and methods can only be used by the class in which they are defined

i.e. can only be accessed within the class

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

What does protected mean?

A

can be used only by other classes in the same package or that inherit from this class

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

Are attributes private or public, generally speaking?

A

private

it maintains the integrity of the object - doesn’t allow other bits of the program to change the object in any way

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

What are getter and setter methods?

A

they allow parts of the program to access and change attributes

you apply them to the variables

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

this

A

use this in a class to refer to class attributes

e. g.
this. radius = radius;

When 2 attributes co-exist, if we don’t use this, the local one (the one passed to the method) is used

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

What does static mean?

A

optional keyword, allows us to have class attributes and methods that can be accessed without creating an instance of the class i.e. an object

if not creating an object and influencing its methods, use static.. - static method as not doing anything to an object.

useful when we want to access methods without the overhead of making objects from that class

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

What can be static?

A

attributes and methods!

*static attributes take the same value for all instances of a class and all objects made from that class e.g. pi = 3.14…

anytime we change the static variable, it changes it for all of them!

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

What is a reference?

A

Person personOne = new Person(“Bill”, 56);

references store the address of the object they refer to

address of the object!

17
Q

What are the scope rules for objects?

A

Objects are available anywhere in our program (as long as there is a reference to that object in its scope)

1 Reference : 1 Object

Many References : 1 Object

18
Q

How can you tell if a new object has been created?

A

new

19
Q

How do we pass objects to methods?

A

via referencing

we tell the method the reference (address).

objects are visible everywhere as long as a reference is present

20
Q

What is the toString() method?

A

The toString() method returns the string representation of the object.

If you want to represent any object as a string