天天看點

private_Keyword

private Java Keyword with Examples

Key points about private Java Keyword

  • A private class member cannot be accessed from outside the class; only members of the same class can access these private members.
  • A class cannot be a private except inner classes because inner classes are nothing but again members of outer class. So members of a class (field, method, constructor and inner class) can be private but not the class itself. We can’t create subclasses to that class which has only private constructors.

    private Java Keyword Example

    Below diagram demonstrates the usage of private access modifier and it’s visibility:

Summary