| Author |
Doubt in accessing a method
|
Prashanth Patha
Ranch Hand
Joined: May 06, 2011
Posts: 56
|
|
Suppose we have a class as follows:
package prash;
public class A // public class
{
void print() { // default access
System.out.print("Hi");
}
}
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
_______________
Prashanth
|
 |
Evelina Vrabie
Greenhorn
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.
|
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
|
 |
 |
|
|
subject: Doubt in accessing a method
|
|
|