The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2000

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:

Very Simple Question

Posted by John Lee on November 16, 2000 at 5:56 PM

//DirectAccess.java
package mylib;

class DirectAccess {
public Integer var = new Integer(10);
}

------------------------------------------------------

//IndirectAccess.java
package mylib;

public class IndirectAccess {
public DirectAccess obj= new DirectAccess();
}

------------------------------------------------------

//client.java
import mylib.*;

class client {
public static void main(String arg[]) {
IndirectAccess ia = new IndirectAccess();
System.out.println(ia.obj.var);
}
}

------------------------------------------------------

compile client.java, got complaint:

client.java:6: The type mylib.DirectAccess to which the member var belongs is
not accessible from class client.
System.out.println(ia.obj.var);
^
1 error


MY QUESTION IS:

in class DirectAccess: wheather var is public or default doesn't make any difference, why wouldn't compiler
complain about this, because if there is no way for any class outside mylib package to access "var", then
its modifier "public" only cause confusion.

Thanks,
John



Replies:

Sponsored Links



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