- Home
- Interview Questions
- Java
Modifiers are just like a keywords of java that gives the compiler information about the nature of code,classes or data. Here the group of modifiers are called access modifiers.
Public is most generous access modifiers in java. Without any restriction we can use any public class, variable or method in any java program. Any subclass may override any public method. we can invoke main() from any java runtime environment once the main() method is declared as public in an application.
Private is a least generous access modifier in java. it may not be declared for top level classes. A private variable may be used only by an instance of the class that declares the variable or method.
Here the rules :
- A private method may be overridden by a private, default, protected, or public method.
- A default method may be overridden by a default, protected, or public method.
- A protected method may be overridden by a protected or public method.
- A public method may be overridden only by a public method.
Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. Abstract classes define an abstraction and leave concrete implementation details to subclasses.