File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes import and extends (need help!!) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "import and extends (need help!!) " Watch "import and extends (need help!!) " New topic
Author

import and extends (need help!!)

tong yuxin
Greenhorn

Joined: Jul 21, 2008
Posts: 19
code:

package a;
public class Father{
//some code...
}
-------------------------------------------------------------------------
package b;
import a.Father
class Son extends Father{
Father a= new Father(); // compiler good.
}
---------------------------------------------------------------------
However if son class like this

package b;

class Son extends a.Father{
Father a= new Father(); // compiler error!
}

So, what's the difference between these two son class. I tried if not use import, just extends a.Father can inheriate the public methods from father class just like use "import"
But why canont get a object of Father?


SJCP 98%
Rodrigo Tomita
Ranch Hand

Joined: Apr 28, 2008
Posts: 70
Tong,

If you are not going to use imports, then you should always write a.Father in all your references to that class. For instance:

Rodrigo Tomita
Ranch Hand

Joined: Apr 28, 2008
Posts: 70
Last but not least, welcome to JavaRanch
tong yuxin
Greenhorn

Joined: Jul 21, 2008
Posts: 19
thanks lot. great help!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: import and extends (need help!!)