This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Creating a package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating a package" Watch "Creating a package" New topic

Creating a package

Deon Smith

Joined: Mar 08, 2002
Posts: 7
I'm trying to create some packages. But I'm getting a compile error when I try to compile the second class in the other package.
package pack1;
public class PackOne {
protected int a = 9;
package pack2;
public class PackTwo extends PackOne {
//do something
I'm getting an error stating that PackOne cannot be resolved.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Deon,
You need to import the package to make its contents visible. So just add:

after the package statment and before the class definition and PackTwo should compile fine.
Hope this helps,
Michael Morris
[ August 11, 2002: Message edited by: Michael Morris ]

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
It is sorta covered in the JavaRanch Style Guide.
subject: Creating a package
It's not a secret anymore!