Posts

Showing posts with the label access modifiers

Java Access Modifiers

Image
                    Access Modifiers This is how we create security by knowing  who accesses a Class , Variable  or Method . Types Of Access Modifiers 1)Public 2)Protected 3)Default 4)Private Public Any class can be access from anywhere. Protected It is visible to the class  it is in and its subclasses and to others in the package it is in. Default Only the class you are in and the people in the package you are in can see. Private Only people in their class can see it. Example 👇                                                                                                                                                   Here class B is Inherited   from class A . Here    class   D is  Inherited   from   class C . Here, if  class A is Private, other   classes and packages cannot access it.  Here , if  class A is Default , B and C classes can access it. (Same package) Here , if   class C  is  Default , they are visible (can access)  to class C,B and A .  can't visible (can