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

class inheritance details

mohan gavande
Ranch Hand

Joined: Oct 07, 2004
Posts: 39
Hi I am new in JAVA. I have some difficulty regarding class inheritance
there r 2-3 types of java class extentions
1) class A interits class B {
}

2) class A extends class B {
}

3) class A impliments class b{
}

And might be many more
So plz tell me details of these differances.
Barry Higgins
Ranch Hand

Joined: Jun 05, 2003
Posts: 89
Of the three classes you've mentioned only two are legal (also watch the spelling on implements)

class A extends class B {
}

class A implements class b{
}

In the cases above
extends denotes that you are inheriting from a class.
implements denotes that you are using an interface. Check out the java tutorial for more information on interfaces.

Also just to mix you up slightly more you can also make an interface extend another interface like this

interface A extends interface B {
}

Post back if you have any more questions!
David Milligan
Greenhorn

Joined: Nov 09, 2004
Posts: 2
When you say about an interface extending another, does the interface refer to a class.
Eric Fletcher
Ranch Hand

Joined: Oct 26, 2000
Posts: 188
Originally posted by David Milligan:
When you say about an interface extending another, does the interface refer to a class.


No, an interface is an interface, not a class. A class can extend a class, and an interface can extend an interface, but a class does not extend an interface nor does an interface extend a class. A class implements an interface.

The concept of interfaces can be tricky to those new to Java. I suggest taking a look at Sun's Java Tutorial especially this section on interfaces.

Hope that helps,
E


My theory of evolution is that Darwin was adopted. - Steven Wright
Barry Higgins
Ranch Hand

Joined: Jun 05, 2003
Posts: 89
By the way apologies for my posting which read

class A implements class b{
}

it should have read

class A implements interface b{
}

Also you should note that you do not include the class/interface word when you use them after extends/implements.

As already mentioned classes and interfaces can refer to very different things and it would be advisable to familiarise yourself with the concepts on the Java Tutorial.
Have fun!
Barry
mohan gavande
Ranch Hand

Joined: Oct 07, 2004
Posts: 39
Actually I am new in JAVA & whatever u discuused is very good & details but as per it is my primary stage so I will read that toutorial & if Any diffuculty will occuer i will contact u again.
Thanks for replying me message.


------------
The main thing in Programming is that it can be do by verious ways
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: class inheritance details