Good morning
I am learning Java and trying to understand the access to class members inside a package.
I have to files in MemberAccess directory and called the package unitOne.MemberAccess(is that right?)
Here is the simple example.
package unitOne.MemberAccess;
public class Parent
{
private String secret = "This is my secret";
protected String inherit = "All my money";
int age = 100;
public void singInShower()
{
System.out.println("la-di-da");
}
}
new I created a seperate file in the same package called OtherPerson.
package unitOne.MemberAccess;
class OtherPerson
{
public static void main(String[]args)
{
OtherPerson op = new OtherPerson();
System.out.println(op.inherit);
System.out.println(op.age);
}
}
The problem is that I get a compile time error explaining to me that the symbol cannot be found.
But in my understanding protected and default members in the same package as another class can be viewed by that class.
Regards
Arian
A member of one class (whether private, public, protected or default) is
Nevervisible to other Class. NEVER….That would be a night mare. Accessing other members and visibility of other members come into play when one class Inherits other class. So either you need to extend class, implement parent child relationship. Then what you are saying would be trueand yes, where I live, its
Good Eveninghere at this point of time 🙂