jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in accessing a method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in accessing a method" Watch "Doubt in accessing a method" New topic

Doubt in accessing a method

Prashanth Patha
Ranch Hand

Joined: May 06, 2011
Posts: 62

Suppose we have a class as follows:

package prash;
public class A // public class

void print() { // default access


Consider another class:

package ravi;
import prash.A;
class B
// Doubt:
// Can B access the method print() (having default access ) of a public class A which is in different package?

Thanks & Regards

Evelina Vrabie

Joined: Oct 10, 2008
Posts: 19
No, default access means package-private (only visible inside the package). Take a look here: http://download.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

Evelina Vrabie
SCJP 6, SCJD (in progress)
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Hello Prashanth, please use code tags to make code reading easier

As you can observe, it is easier to read now.

In Your Pursuit Towards Certification, NEVER Give Up.
I agree. Here's the link: http://aspose.com/file-tools
subject: Doubt in accessing a method
It's not a secret anymore!