There are three types of access modifiers in Java. public, private, protected. If no access modifier is specified then it has a default access.
Object-oriented programming is used to set access modifiers, which control how accessible Java classes, constructors, methods, and other members are. We can control the scope or accessibility of these classes, methods, constructors, and other components using the access modifiers.
Access Modifiers in Java code example
- class A{
- protected void msg(){System.out.println(“Hello java”);}
- }
- public class Simple extends A{
- void msg(){System.out.println(“Hello java”);}//C.T.Error.
- public static void main(String args[]){
- Simple obj=new Simple();
- obj.msg();
Related Posts for Java
- Core Java Interview Questions with Answers (2023)
- Difference Between C++ and Java
- The Main Method in Java
- Features of JSP
- Difference between Java Servlet and CGI
- Difference between JSP and ASP
- Difference Between JSP and PHP
- Features of JavaScript#
- Servlet JSP Interview Questions for Java

Related Posts
Analog and Memory Layout Design Forum |
Physical Layout Design Forum |
RTL & Verilog Design Forum |
Semiconductor Forum |
Analog Layout Design Interview Questions | Memory Design Interview Questions |
Physical Design Interview Questions | Verilog Interview Questions |
Digital Design Interview Questions | STA Interview Questions |