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()
2
Q
Static data fields can be directly accessed by what type of methods?
A
Both static and non-static methods
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
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 = “ “