• Post Reply Bookmark Topic Watch Topic
  • New Topic

doudts on extends object class  RSS feed

 
Arpitha Ramesh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
All class in java by default extends the object class.
For instance
class A extends object
{
}
Now consider this,
class A extends B
{
}

as all classes extends object by default then the above class will be
class A extends B extends object
{
}

But java says,we can't extend two class.Then How is the above class interpreted.

Thanks,
Arpitha
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not allowed to directly extend more than one class, but you indirectly extend class up to Object.

For example, the JPanel class extends JComponent which extends Container which extends Component which extends Object.

JPanel is a direct subclass of JComponent, but an indirect subclass of Container, Component, and Object.

Because of the Java hierarchy, JPanel indirectly extends Container, Component, and Object, and inherits all fields and methods that are allowed to be inherited from them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!