This concept is introduced in C++ . In C++ keywords (Reserved words) are categorized in two categories like access specifiers and access modifiers. Now, we will see keywords categorization in access specifiers and access modifiers.
•Access Specifiers: private, public,protected and default. These four keywords are introduced in C++ as access specifiers.
•Access Modifiers: static, abstract , synchronize, strictfp, native etc. All keywords except private, public, protected and default are introduced in C++ as access modifiers.
For Example: With the help of an example we can see that private is not an access modifier in C++.
#include <iostream>
using namespace std;
class AccessSpecifers{
private:
int x ;
};
int main(){
AccessSpecifers ob;
ob.x = 10;
}
Error:
Main.cpp:12:8: error: 'x' is a private member of 'AccessSpecifers'
ob.x = 10;
Explanation:
In the above program, we are getting an error “ 'x' is a private member of 'AccessSpecifers' ” due to a private member. As we all know, private members can’t be used outside of class “AccessModifiers”. But we have to confirm whether “private” is introduced in c++ as access modifiers or not. So it is clear “private” is not considered as access modifiers.
But, In Java there is no such concept or such terminology as access specifiers that means all keywords(Reserved words) are categorized in one and only one category i.e. access modifiers.
•Access Modifiers: private, protected, public, default, static, synchronize, abstract, native, strictfp etc. All keywords are introduced in java as access modifiers.
For Example: With the help of an example we can see that private is access modifiers in java.
private class AccessModifiers {
public class Main{
}
}
Error:
/Main.java:1: error: modifier private not allowed here
private class AccessModifiers {
^
1 error
Explanation:
In the above program, we are getting an error “modifier private not allowed here” due to private modifier. As we all know, private modifiers can’t be used with a top level class named “AccessModifiers”. But we have to confirm whether “private” is introduced in java as access modifiers or not. So it is clear “private” is considered as access modifiers.