Access Modifiers Flashcards

1
Q

Access Modifiers / Visibility Modifiers

A
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

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

Non Access Modifiers

A
  1. Static

2. Final

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

Access Modifiers & Non Access Modifiers

CLASS

A
  • 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";
   }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Access Modifiers & Non Access Modifiers

CONSTRUCTOR

A

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)

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

Access Modifiers & Non Access Modifiers

INSTANCE VARIABLES

A

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

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

Access Modifiers & Non Access Modifiers

METHODS

A

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

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