Access modifier is keyword to change visibility of variable,class, constructor or methods. Access modifier will be used according to our need, how and where we want to use those variable,class, constructor or methods.
public class Android{private void show(){//some code here.}}
they are visible to package. To make class, variable, constructor or methods visibility to default then we don’t need to use any keyword.
class Android{}
This class Android will be accessible to any class within same package.
As its name says, it makes the visibility to class only. Which means if any variable or method of a class have access modifier to private then it will only visible inside its class.
class Android{private void show(){//This is private method and visible inside only this Android class.}}
Protected access modifier change the visibility to package and subclass only. Subclass means if class Android extends class Java, and class Java have protected method then ot will be accessible inside Android class.
class Java {protected void run(){System.out.println("accessed from derived class");}}class Android extends Java{private void show(){run(); // protected method of java class called here.}}
Public access modifier change the visibility to the world , which means they are accessible anywhere in the project.
public class Java{public void show(){System.out.println("public method called");}}
Quick Links
Legal Stuff
Social Media