• 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

can a class extend two classes

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i know that a class can extend only 1 class. But it is said that every class has object class as its super class . So it says that if a class A extends class b and also class object.
is it true. is it a valid doubt.
please give me a idea wat exactly is happening.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What makes a "doubt" a "valid doubt"? I think you need to read about single inheritance versus mulitple inheritance and the basic notion of a class hierarchy. Java has single class inheritance. When you define a class you can write

class B extends X {...}

but not

class B extends X, Y {...} //as one can do in C++, for example.

Because you can continue this process and define a class to extend B:

class C extends B {...}

a hierachy may result. Consider javax.swing.JButton:

JButton extends AbstractButton
AbstractButton extends JComponent
JComponent extends Container
Container extends Component
Component extends Object

Because at each step the newly defined class can only *directly* extend one class, this is not multiple inheritance.
[ May 19, 2006: Message edited by: Jeff Albertson ]
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All classes inherit one and only one class - with the single exception of java.lang.Object - which does not inherit from any class. All classes inherit directly (implicitly or explicitly) or indirectly from java.lang.Object - again with the exception of java.lang.Object itself.

 
this is supposed to be a surprise, but it smells like a 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