943,675 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 632
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 26th, 2009
0

Multiple Inheritence

Expand Post »
I know java doesnot support multiple inheritence.lets say my class A extends B.Now my class A is extending class B as well as Object Class .how this happens?Why class A gets compiled?
Last edited by sarath.koiloth; Sep 26th, 2009 at 5:49 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
sarath.koiloth is offline Offline
30 posts
since Sep 2006
Sep 26th, 2009
0

Re: Multiple Inheritence

You can inherit from a single parent downwards as far as you want...
A extends Object; B extends A; C extends B; etc
Thus, by implication, C extends B, A, and Object.
What you can't do is this:
E extends F,G
ie. extend from two parents at the same level. This is what Java refers to a multiple inheritance.
Last edited by JamesCherrill; Sep 26th, 2009 at 9:57 am.
Featured Poster
Reputation Points: 1907
Solved Threads: 950
Posting Expert
JamesCherrill is online now Online
5,767 posts
since Apr 2008
Sep 26th, 2009
0

Re: Multiple Inheritence

The language was setup so that you can't have multiple inheritance. If you want multiple inheritance, you have to use interfaces. By using keyword "implements" in the class heading.

extends - for classes
implements - for interfaces
Reputation Points: 10
Solved Threads: 4
Light Poster
jmaat7 is offline Offline
29 posts
since Sep 2009
Sep 26th, 2009
0

Re: Multiple Inheritence

Yeah interfaces are somewhat similar - if your class "implements" the interface, it forces you to include those methods that are defined in the interface itself.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Sep 28th, 2009
0

Re: Multiple Inheritence

Thanks for the replies.I want to know how these implementation happens.ie extending object class invisibly and extending to Other class explicitly.
Reputation Points: 10
Solved Threads: 0
Light Poster
sarath.koiloth is offline Offline
30 posts
since Sep 2006
Sep 28th, 2009
0

Re: Multiple Inheritence

In effect, if your class does not explicity specify an "extends" superclass, then the superclass is taken to be Object. It's that simple.
Featured Poster
Reputation Points: 1907
Solved Threads: 950
Posting Expert
JamesCherrill is online now Online
5,767 posts
since Apr 2008
Sep 29th, 2009
0

Re: Multiple Inheritence

ok.So it is multiple inheritence right.extending to two classes.How jdk peoples implemented that ?
Reputation Points: 10
Solved Threads: 0
Light Poster
sarath.koiloth is offline Offline
30 posts
since Sep 2006
Sep 29th, 2009
0

Re: Multiple Inheritence

It's single inheritance. Each class inherits from 1 class only, but that class, in turn,inherits from one class, etc, all the way up to Object.
When your code refers to a method or variable in a class Java looks for that method/variable in the class definition. If it finds it, OK. If not, it looks in the definition of the superclass. If it finds it there, OK. If not, it looks in that classes' superclass etc, all the way to Object. I it doesn't find it in Object you get a compile error.
Featured Poster
Reputation Points: 1907
Solved Threads: 950
Posting Expert
JamesCherrill is online now Online
5,767 posts
since Apr 2008
Sep 29th, 2009
0

Re: Multiple Inheritence

Anyway its extending the object class. Or How these Object class is made super class to our class. How our class know that Object class is super class with out explicitly extending?
Reputation Points: 10
Solved Threads: 0
Light Poster
sarath.koiloth is offline Offline
30 posts
since Sep 2006
Sep 29th, 2009
0

Re: Multiple Inheritence

That's part pf the language definition. If you don't specify an "extends" then your class extends Object. It's built into the compiler.
Featured Poster
Reputation Points: 1907
Solved Threads: 950
Posting Expert
JamesCherrill is online now Online
5,767 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Error Scanner Loading
Next Thread in Java Forum Timeline: HELP<!>Program doesn't get user input from the 2nd Textfield(KAEquation)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC