📜  Java中公共,私有和受保护修饰符之间的区别? - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:14.434000             🧑  作者: Mango

代码示例1
• In Java, access modifier which specifies accessibility of class, 
    methods and variables. There are four access modifiers in 
    Java namely Public, Private, Protected and Default. 
• The difference between these access-modifies is that; 
o The most importantly is the level of accessibility. 
o Public is accessible to anywhere 
o Private is only accessible in the same class which is declared 
o Default is accessible only inside the same package 
o Protected is accessible inside the same package and also 
    outside the package but only the child classes. 
• We cannot use private or protected modifier with a top--level class. 
• We should also keep in mind that access modifier cannot 
    applied for local variable public, private or protected in Java.