aspose file tools
The moose likes Java in General and the fly likes inheritance (need help) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

inheritance (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%
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

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.


[Jess in Action][AskingGoodQuestions]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

Sigh. Answered here, too. Please don't waste people's time this way! See here for help in understanding what I mean.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: inheritance (need help)
 
Similar Threads
doubt
Generic question
please multi level inheritence in protected?
import and extends (need help!!)
Iterator of an ArrayList