Access Specifiers in Java- Key Points

  • Encapsulation links data with the code that manipulates it. 
  • Encapsulation provides another important attribute called access control.
  • Java’s access specifiers are public, private, and protected.
  • A default access level is also defined in Java.
  • protected applies only during inheritance.
  • When a member of a class is declared as public, then that member can be accessed by any other code.
  • When a member of a class is declared as private, then that member can only be accessed by other members of its class.
  • When no access specifier is used, then by default the member of a class is public within its own package, but cannot be accessed outside of
  • its package.  
  • main( ) method in Java is declared as public because it is called by code that is outside the program—that is, by the Java run-time system.  

Abstract Methods and Classes in Java-Key Points

  • The methods that are declared but not implemented are called abstract methods.
  • An abstract class can contain abstract methods and fully implemented methods both.
  • All of the methods in an interface  are implicitly abstract, so the abstract modifier is not used with interface methods.
  • If an abstract class contains only abstract method declarations, it should be declared as an interface instead.
  • Unlike interfaces, abstract classes can contain fields that are not static and final, and they can contain implemented methods.