Static Methods/Fields Flashcards

1
Q

How are static methods and fields accessed
Ex: Class MyClass contains static methods and fields

A

Static methods and fields are accessed via their class name
Ex: MyClass.field or MyClass.method()

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

Static data fields can be directly accessed by what type of methods?

A

Both static and non-static methods

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

Which type of fields can a static method directly access?

A

Static methods can only access static fields directly, without the help of a reference variable

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

What happens if static fields, int, boolean, reference-variable or char are not initialized?

A

They are initialized with default variables:
int = 0
boolean = false
reference-variable = null
char = “ “

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