Multiple Inheritence

Reply

Join Date: Sep 2006
Posts: 30
Reputation: sarath.koiloth is an unknown quantity at this point 
Solved Threads: 0
sarath.koiloth's Avatar
sarath.koiloth sarath.koiloth is offline Offline
Light Poster

Multiple Inheritence

 
0
  #1
Sep 26th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 145
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: Multiple Inheritence

 
0
  #2
Sep 26th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 23
Reputation: jmaat7 is an unknown quantity at this point 
Solved Threads: 3
jmaat7 jmaat7 is offline Offline
Newbie Poster

Re: Multiple Inheritence

 
0
  #3
Sep 26th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,580
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 200
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Multiple Inheritence

 
0
  #4
Sep 26th, 2009
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.
Out.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 30
Reputation: sarath.koiloth is an unknown quantity at this point 
Solved Threads: 0
sarath.koiloth's Avatar
sarath.koiloth sarath.koiloth is offline Offline
Light Poster

Re: Multiple Inheritence

 
0
  #5
Sep 28th, 2009
Thanks for the replies.I want to know how these implementation happens.ie extending object class invisibly and extending to Other class explicitly.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 145
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: Multiple Inheritence

 
0
  #6
Sep 28th, 2009
In effect, if your class does not explicity specify an "extends" superclass, then the superclass is taken to be Object. It's that simple.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 30
Reputation: sarath.koiloth is an unknown quantity at this point 
Solved Threads: 0
sarath.koiloth's Avatar
sarath.koiloth sarath.koiloth is offline Offline
Light Poster

Re: Multiple Inheritence

 
0
  #7
Sep 29th, 2009
ok.So it is multiple inheritence right.extending to two classes.How jdk peoples implemented that ?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 145
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: Multiple Inheritence

 
0
  #8
Sep 29th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 30
Reputation: sarath.koiloth is an unknown quantity at this point 
Solved Threads: 0
sarath.koiloth's Avatar
sarath.koiloth sarath.koiloth is offline Offline
Light Poster

Re: Multiple Inheritence

 
0
  #9
Sep 29th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 145
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: Multiple Inheritence

 
0
  #10
Sep 29th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC