aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why public? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why public?" Watch "Why public?" New topic
Author

Why public?

Shravan Durvasula
Greenhorn

Joined: Mar 06, 2004
Posts: 19
Hello all:
This is one of my interfaces:

This is a class that implements the interface:

The compiler is asking me to make the implemented method (methodB in MainClass) public.
But in the original interface (InterfaceA) the scope of methodA is package. Then why do i need to make it public in the implemented class?
Thanks and Regards,
-skd
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
From the JLS, §9.4 Abstract Method Declarations:

Every method declaration in the body of an interface is implicitly public.

Corey


SCJP Tipline, etc.
Shravan Durvasula
Greenhorn

Joined: Mar 06, 2004
Posts: 19
Thanks Corey.
"How can i have an interface whose methods can be implemented only within the package?"
Does the above question make sense because now i understand that everything in an interface is public?
Thanks,
-skd
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Shravan Durvasula:
"How can i have an interface whose methods can be implemented only within the package?"

You can't. All methods defined within an interface are implicitly public. It is a compiler error to override a method with a more restrictive access modifier.
If you want that sort of functionality, you'll have to extend a class that has methods assigned the "default" access modifier.
Corey
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why public?