Hey viewers, welcome to my blog. Today I Will be explaining about Access Specifier in java.
Now you might be having a number of questions in your mind. For example –
- What are Access, Specifiers?
- Where are they used? and
- How are they used? etc.
Don’t worry I will be answering all these questions.
Let’s get started,
These specifiers are used to restrict the scope of a class, constructor, variable, method or data member. These are also known as Access Modifiers.
There are different kinds of access specifiers which are as follows:-
- Default – No keyword required
Now let’s understand these access specifiers one by one default: If no access modifier is specified for a class, method or data member, then they act as a default access modifier. They are accessible only within the same package.
Example:- 2. Private:
Moving forward,this is specified using the private keyword.
Data members or methods declared as private are accessible only within the class in which they are declared. Other class of the same package will not be able to access these members. Class and interfaces cannot be declared private.
Data members or methods declared as protected are accessible within same package or subclasses in the different package.
This is specified using the public keyword.
It has the widest scope among all other access modifiers. Classes, data members or methods declared as the public are accessible from everywhere in the program.
Example:- I hope this article help you understanding the concept of Access Specifiers in JAVA.
For more such content subscribe to our YouTube channel –https://www.youtube.com/channel/UCcWR1IezEQynJnAETgK8g2w?sub_confirmation=1 and follow us on facebook – https://www.facebook.com/pristinetechschool
Happy programming !!