my dog learned polymorphism
The moose likes Beginning Java and the fly likes A BIG Question Concerning Packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A BIG Question Concerning Packages" Watch "A BIG Question Concerning Packages" New topic

A BIG Question Concerning Packages

Gary Farms
Ranch Hand

Joined: Jun 24, 2000
Posts: 57
If I call a method in ClassB from main in ClassA, why is it that both classes must be in the same package, and ClassB must extend Class A?
I found all of this out tonight (the hard way), when I finally got my main method to call a function in another class. The ONLY way it would compile and run was to declare both class files in the same package, and have the called class (containing the function I was calling)to extend the class containing main (the caller).
Can anyone tell me why Java requires all of this?? No wonder this language is so difficult to grasp by just reading Java books?
Roy Tock
Ranch Hand

Joined: Jul 16, 2001
Posts: 83
Gary, it's not true. Check out my reply to your previous post for an example. You'll notice that MyTest is not in MyClass's package, MyTest does not extend MyClass, and yet it all compiles and runs.
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
See my reply to your other post. What you say here just is not true.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
I agree. Here's the link:
subject: A BIG Question Concerning Packages
It's not a secret anymore!