Tutorialslot.com

youtube facebook twitter gmail pinterest

Access Modifiers in Java

1) Public
It allows the programmer to control the visibility of class members. When a class member is preceeded by public, then that member may be accessed by code outside the class in which it is declared.

2)Private
The private access specifier is just the opposite of public.It prevents a member from being used by code defined outside of its class.

3)Protected
Variables and methods declared protected are accessible from the classes defined in the same package and also from subclasses which are defined in other packages.

4)Default
we do not explicitly declare an access modifier for a class, field, method, etc.A variable or method declared without any access control modifier is available to any other class in the same package. The fields in an interface are implicitly public static final and the methods in an interface are by default public.



Advertisement Powered By Google Adsense






IF YOU LIKE THIS TUTORIALS PLEASE SHARE

Share on whatsapp

POPULAR TAGS

Java java tutorials learn java java programming tutorial learn java online learning java professionals tutorials Multithreading Generics Object Oriented Language Methods Polymorphism Inheritance