This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Will every class inherit the object class?

 
Chandra Bairi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends,
I have a doubt. Ihave read that every class extends java.lang.Object class implicitly. Does this hold for an interface also? Does a interface extend the java.lang.Object methods?
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.
When some class implements the interface by default the class also extends java.lang.Object.
 
Tom Wolve
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simple rule is
interfaces can extend interfaces, but not classes.
classes can extend classes, but not interfaces.
 
Donald R. Cossitt
buckaroo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interface is essentially a collection of constants and abstract methods. To make use of an interface, you implement the interface in a class - that is, you declare that the class implements the interface and you write the code for each of the methods declared in the interface as part of the class definition.
Check
Learning the Java Language
What is an Interface?
Implementing an Interface

At Java Sun
HTH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic