Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A BIG Question Concerning Packages" Watch "A BIG Question Concerning Packages" New topic
Author

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
Sheriff

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


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A BIG Question Concerning Packages
 
Similar Threads
Defining Generics of subclassed objects?
Method design problem
class loader