difference between public private and protected in class members code example

Example: 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.

Tags:

Java Example