The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Access to private member of super-class

Posted by Andre Mahl on July 18, 2001 at 8:26 AM

I have coded two classes (in the same package):

public class A {
private int i;
// here are also getI and setI Methods implemented
}

public class B extends A {
...
void X() {
i = 42;
}
...
}

The line "i = 42;" results in an error message:
Error: variable i has private access in class A

I thought, when extending a class the child-class (B) gets the member i and the corresponding getI and setI Methods.
So, as i is now also a member of class B I should be able to access it inside class B anyway...

But this is not the fact. Why?

PS: I am of course able to access it via the getI and setI methods - but this seems to be programming around the corner - isn't it...





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us