aspose file tools*
The moose likes Beginning Java and the fly likes Queston about Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Queston about Inheritance" Watch "Queston about Inheritance" New topic
Author

Queston about Inheritance

howie jao
Greenhorn

Joined: Nov 08, 2009
Posts: 14
Hi all,

I have an question about inheritance. I am wondering how can I achieve below situation.
Class C extend Class B
Class B extend Class C

I want a class that can extend from B only . not A . Not C .

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

You can't have C extends B and B extends C. You can have a class that extends B only, not A or C. Could you be clearer about what you want to do?
howie jao
Greenhorn

Joined: Nov 08, 2009
Posts: 14
Sorry that I have not been clear.

If currently I have 3 classes: A, B, C .
C extend B
B extend A

Is is possible to have a new class ,ie: D that only extend B but not A or C ?
Because I know that if this new class extend B then it will extend A . is thers a way that this can be happening. Just curiosity.
Bert Wilkinson
Ranch Hand

Joined: Oct 28, 2009
Posts: 33
If you "extend" a class, you automatically extend everything ABOVE IT in the chain. So, in your example, if D extends B it would also extend A by definition, but it would not, and cannot extend C.

if you're contemplating complicated extends relationships, you might want to research interfaces, which are easier with lateral relationships.

howie jao
Greenhorn

Joined: Nov 08, 2009
Posts: 14
Thank you Bert for you response. I personally agree that. I am just wondering if there is trick to that. =)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36520
    
  16
You would find it easier to understand if you drew UML class diagrams on a sheet of paper.
Vlad Varnica
Ranch Hand

Joined: Dec 28, 2002
Posts: 40
Here it is


[Thumbnail for inheritence.png]

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Queston about Inheritance
 
Similar Threads
multiple inheritence in core java
Object class by default break to rule of multipul inheritance
Does JAVA support multiple inheritance or not
Java Doesn't support Multiple inheritance
can a class extend two classes