This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "different packages" Watch "different packages" New topic

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?
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056

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

Joined: Aug 05, 2002
Posts: 787
Thanks Ron
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: different packages
It's not a secret anymore!