Answers for "public and private and protected in java"

1

java protected private public

public      >> class, package, subclass (same pkg), subclass (diff pkg), world
protected   >> class, package, subclass (same pkg), subclass (diff pkg)
no modifier >> class, package, subclass (same pkg)
private     >> class
Posted by: Guest on August-31-2021
0

Difference between Public, Private and Protected modifier in Java?

• 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.
Posted by: Guest on May-16-2021

Code answers related to "public and private and protected in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language