wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package " Watch "Package " New topic
Author

Package

Bindu San
Greenhorn

Joined: Mar 08, 2002
Posts: 5
Hi
I am writing a class "Date" in package "A".
And writing a class "Employee" in package "A"
(i am creating an object of DATE in class EMPLOYEE)
And then, i am inheriting the class "Employee" to a subclass "Boss" . Now, what classes are supposed to be placed in package "A" and does Boss needs an import statement ?
And, when we create a package, do we have to create a directory before hand ???
I appreciate some help .
Thankyou.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Bindu San:
Now, what classes are supposed to be placed in package "A" and does Boss needs an import statement ?

Well, you can place whichever classes you'd like inside package A. Packages are really designed to help you organize your classes. They can, however, be used to help set up accessibility to members.
The rule of thumb about imports is that, unless the class you're trying to get at is in the same package as the one the class that's trying to get at it is in, you'll need to designate the full name of the class. Take a look at this example:

The code above is illegal because the compiler can't find a class called Parent within package B (which is where class Child is). You have two options to resolve this - you can use an import statement or you can provide the fully qualified name of class Parent. If you replace the last line in the above example with either of these options, you'll be fine.

I hope this helps you understand how to deal with packages. If you have more questions, please ask.
Corey


SCJP Tipline, etc.
Bindu San
Greenhorn

Joined: Mar 08, 2002
Posts: 5
Hi Corey ,
Thats a great help. But what i did is , i placed all my classes in the same package. If this is the case, will my import statement give any problem ???
Coz, i declared classed A and B in the same package. And B extends A. In the class B, i used an import statement,. Is this necessary ???
Still my program is in trouble...
Plz help me out
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Hello,
If I'm understanding you correctly...
No, you don't need to import the package that your class is already in. So:
package a;
import a.*; // unnecessary
class A {
}
Let me recommend Controlling Access To Members Of A Class as a good source of information straight from the horse's mouth.
Good Luck,
-Dirk Schreckmann


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Package