Core Java 5: Static vs non-static & final keyword Flashcards

(6 cards)

1
Q

Static

A

belongs to class definition rather than to a specific instance.

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

Where is static useful?

A
  • Constants (public final static)
  • Utility methods: methods which take action on given data type & do not require any internal state
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why does static break encapsulation?

A
  • Static attributes can be manipulated without having to use instance
  • Can change the state an object depends on without talking to class directly
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

final (classes)

A

if a class is marked as final, it can’t be extended/inherited from.

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

final (methods)

A

if a method is marked as final, it can’t be overridden.

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

final (attributes)

A

if an attribute is marked as final, it can’t be modified; often used for constants, such as pi.

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