aspose file tools*
The moose likes Beginning Java and the fly likes difference between java acces specifiers? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "difference between java acces specifiers?" Watch "difference between java acces specifiers?" New topic
Author

difference between java acces specifiers?

vani geetha
Greenhorn

Joined: Jan 18, 2008
Posts: 2
I need breif difference in private, public, protected, default.
Lukasz Bajzel
Greenhorn

Joined: Dec 03, 2007
Posts: 26
The access modifiers in Java are 'public, private, protected, or package-private (no modifier)'

In Java there are two levels of access control.

1. The class level or top level (public or package-private access)
2. The memeber level (public, private, protected, or package-private)

The class level:

When a class is declared 'public', it is visible across packages. But when it is defined package-private or default (that is without any modifier), the class is visible only to other classes within the same package.

public class JavaAdvice -> visible across packages.
class JavaAdvice -> visible only within the package.

At the class level only public or default access are allowed

--

The memeber level:

The following table shows the access to members permitted by each modifier.

Access Levels:

Modifier Class Package Subclass World
-------- ----- ------- ------- ------
public Y Y Y Y
protected Y Y Y N
no modifier Y Y N N
private Y N N N


In Summary,
A class can be defined public or default (no modifier) and class members are allowed to have one of 'public, private, protected, or package-private (no modifier)'. Public members are visible across packages. Any private member of a class is not visible outside of the class. Any protected members are available to the class and its subclass. Default members are visible in the class and within the same package.



Hope this helps!

Sincerly,
Your friends at www.javaadvice.com
www.javaadvice.com - The place where your questions are answered directly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between java acces specifiers?