• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

class inheritance details

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say about an interface extending another, does the interface refer to a class.
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Barry Higgins
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Don't listen to Steve. Just read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic