Access Modifiers Flashcards
Access Modifiers / Visibility Modifiers
PUBLIC -> PROJECT PRIVATE-> CLASS Protected -> determined by parent child relationship - NO INHERITANCE -> default -> PACKAGE - INHERITANCE -> public -> PROJECT
if non of the above are provided then it will be DEFAULT -> PACKAGE
Non Access Modifiers
- Static
2. Final
Access Modifiers & Non Access Modifiers
CLASS
- Class can be public or default
- Class can be final: cannot be parent anymore
- Inner class can be static
- Outer class cannot be static
public class Table{ public static DiningTable{ public static String material = "wood"; } }
Access Modifiers & Non Access Modifiers
CONSTRUCTOR
private constructor: create object in same CLASS
default constructor: create object in same PACKAGE
protected constructor: based on having inheritance
- NO INHERITANCE -> default -> PACKAGE
- INHERITANCE -> public -> PROJECT
public constructor: create objects in PROJECT
Can never be static nor final (compiler error)
Access Modifiers & Non Access Modifiers
INSTANCE VARIABLES
private instance variables: CLASS
default instance variables: PACKAGE
protected instance variables: based on inheritance
- NO INHERITANCE -> default -> PACKAGE
- INHERITANCE -> public -> PROJECT
public instance variables: PROJECT
static instance variable: it belongs to Class and can be called with class name
final instance variable: it has an initial value instantiated in the Class and this initial value can never be changed
Access Modifiers & Non Access Modifiers
METHODS
private methods: CLASS
default methods: PACKAGE
protected methods: based on inheritance
- NO INHERITANCE -> default -> PACKAGE
- INHERITANCE -> public -> PROJECT
public methods: PROJECT
static methods: it belongs to class and can be called with class name
final methods: can not be overridden