aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes different packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "different packages" Watch "different packages" New topic
Author

different packages

Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
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....
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
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
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
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
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Both.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Thanks Ron
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: different packages