• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A BIG Question Concerning Packages

 
Gary Farms
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my reply to your other post. What you say here just is not true.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic