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?
If you don't use the import, then by definition you must say
a.Father = new a.Father();
That's all that "import" does: it tells the compiler that when you say "Father", you actually mean "a.Father". Without the import, the compiler has no idea what "Father" you mean.