• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

import and extends (need help!!)

 
tong yuxin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rodrigo Tomita
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Last but not least, welcome to JavaRanch
 
tong yuxin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks lot. great help!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic