DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Inheritance (http://www.daniweb.com/forums/thread165189.html)

Simran1 Dec 31st, 2008 6:31 am
Inheritance
 
Hello,
Please tell me in Java we don't have a multiple inheritance? so,in which function we use these inheritance.

Thanks

javaAddict Dec 31st, 2008 6:42 am
Re: Inheritance
 
Quote:

Originally Posted by Simran1 (Post 767864)
Hello,
Please tell me in Java we don't have a multiple inheritance? so,in which function we use these inheritance.

Thanks

You say:
> we don't have a multiple inheritance
but then you ask:>in which function we use these inheritance

The only thing I can say is that java doesn't have multiple class inheritance, but multiple Interface implementation.

If that doesn't cover you, ask a better question

chili5 Dec 31st, 2008 2:30 pm
Re: Inheritance
 
What do you mean?

There isn't multiple inheritance in Java. It's a single inheritance only language. :)

jasimp Dec 31st, 2008 7:41 pm
Re: Inheritance
 
Quote:

Originally Posted by chili5 (Post 768138)
What do you mean?

There isn't multiple inheritance in Java. It's a single inheritance only language. :)

That's what javaAddict said, Java does not have multiple class inheritance, you can only only extend (is-A) one class. However you can implement (has-A) any amount of interfaces you want.

vijendtra Jan 1st, 2009 2:04 am
Re: Inheritance
 
Quote:

Originally Posted by Simran1 (Post 767864)
Hello,
Please tell me in Java we don't have a multiple inheritance? so,in which function we use these inheritance.

Thanks

c there is no concept of multiple inheritance in java but some time it seems that there may be a multiple inheritence....

parthiban Jan 1st, 2009 3:30 am
Re: Inheritance
 
Quote:

Originally Posted by jasimp (Post 768293)
That's what javaAddict said, Java does not have multiple class inheritance, you can only only extend (is-A) one class. However you can implement (has-A) any amount of interfaces you want.

Hi Sriran1 ,

what jasimp said is correct expect that implementing a interface is *NOT* mean "Has-A" relationship.

Has-A relationship is what when an Class has other Class's object in it's attribute

Implementing a interface is also means "Is-A" relationship

e.g
//for Is-A 
class Mammal {
}

class Dog extends Mammal { }

//for Has-A

class Tail { }

class Dog extends Mammal { // Dog IS-A mammal
  Tail tail ;    //  and Has-A Tail
 }


All times are GMT -4. The time now is 4:46 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC