Access Modifiers


                 Class , Varaible , Method  - Java

Security - [( Class , Variable , Method ) (Access -Yes/No)}

★( Class,  variable , method ) The ability to access and not access is determined according to the security (modification) given to access.

Access Modifiers What are the 4 types?

               ★   Public

               ★   Protected

               ★   Default

               ★   Private



Public

(class variable methods) If the project is public, this (class variable method) accesses any class in any package.

  Ex :                                                     Human

                Human Java Package -   Human

                                                            Human Java - (Human package / java class)

                 Man Java Package     -   Man          - 

                                                            Man Java     -  (Man package / java class)

                  Child Java Package   -   Child

                                                            Child Java  - (Child package / java class)

Protected                 

class (when protected is run inside the class) package (protected class is inside the package) sub class (protected class is inside the sub class that is formed as the supper class) Protected class variable method access.

  Ex :                Human

                         Human

                         Human Java 

                         Human 1.Java 

                         Man

                         Man .Java

Human 1.java

Protected void run () {

}

Man .java - run ();  =  Access


Human.java 

Protected void eat () { 

}

Human 1.java

Class Human 1 extends human {

Eat (); = access 

}

Default

class (in the default class) package (in the package of the default class) default class, variable, method access.

Ex : Human.java 

       Default class human 

       (Default) void run () {

       }

        Class human = extends human {

        Run ();          = access

        }

        } 

Private

       Only class (private class) can access private class, variable, method. 

class man extends human { (private does not get anything from human.

}

Ex : Private class human {

        Private String d;

        d = "abc12";

        Private int a = 10

        Int b = 5;

        Int c = int a + (private) int b; =   Access

       Private void run () {

       }

       }


                                                                                                                                                D.M.T. Dasanayaka
                                                                                                                                               Software Engineer                                                                                                                                                                                          Java Development.

Comments