•Java provides a number of access modifiers to set access levels for classes, variables, methods and constructors. The four access levels are:
1.Visible to the package. the default. No modifiers are needed.
2.Visible to the class only (private).
3.Visible to the world (public).
4.Visible to the package and all subclasses (protected).
•Default access modifier means 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.
•If you want only objects in the same class to be able to get or set the value of a field or invoke a method, declare it private.
•If you want any object at all to be able to call a method or change a field, declare it public.
•If you want access restricted to subclasses and members of the same package, declare it protected.
1.Visible to the package. the default. No modifiers are needed.
2.Visible to the class only (private).
3.Visible to the world (public).
4.Visible to the package and all subclasses (protected).
•Default access modifier means 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.
•If you want only objects in the same class to be able to get or set the value of a field or invoke a method, declare it private.
•If you want any object at all to be able to call a method or change a field, declare it public.
•If you want access restricted to subclasses and members of the same package, declare it protected.
This helped me write my assignment,Thankyou!!!
ReplyDeleteGlad ^^
DeleteThnx
ReplyDeleteThnx
ReplyDeletethanx
ReplyDelete