Suppose you want to write following statement: Shape s = new circle() Whereas circle is a type of Shape. If Shape and circle both happen to be in different package, do they both have to Public or just Shape can be public only....
That depends where the statement is. If it's in a class within the package in which Shape is defined, you will need to import circle and circle must be public. However if it's in a class within the package where circle is defined, it's necessary to import Shape and Shape must be public. That is, a class needs to be public if is going to be referred from another package in which was declared. [ August 15, 2002: Message edited by: Jose Botella ]
SCJP2. Please Indent your code using UBB Code
Joined: Aug 05, 2002
So here is the scenario: Shape and Circle both in same package. The client class that is calling these classes with statement: Shape s = new Circle; is in a different package. Do we have to have Shape and Circle both public or only one of them? Thanks