With the use of access modifiers we can restrict the scope or visibility of a package, class, constructor, methods, variables, or other data members. It is also known as access specifiers or visibility specifiers.
There are four types of modifiers as follows:
if we do not specify the access, it is public by default
the public access modifier is accessible everywhere. This is the default access modifier in java and hence it has the wide scope
strict accessibility within the class only
If we try to access the private member from outside the class, it will end up in a compilation error
Website income is: 40000.0
Knowledge2life Bouns: 10000
Only through inheritance, this access modifier is used. This can be applied to data member, constructor and method.