3

In this tutorial (http://www.studytonight.com/java/object-and-classes) I read that a java class may optionally extend one parent class. By default, it will extend java.lang.Object.

Note: important statement that i was read that Java enums extend the java.lang.Enum class implicitly, so your enum types cannot extend another class.

according to note our normal java class should not extend other class like enum (enum types cannot extend another class).but we can able to inherit one class. is this multiple inheritance.?

in java class can derived by extends keyword. like this

class SomeClass
 { }
class MyClass extends SomeClass{}

How can all java classes by default extends java.lang.Object class without extends keyword in java?

When our class extends some base class, it becomes multiple inheritance. I searched in stackoverflow, but still I am not clear. By default any class extends Object class. Doesn't it mean java supports multiple inheritance?

Can anybody clarify this with a simple example.

4
  • In Java every class is implicitly derived from class Object. If you make your own class, you don't need to use the keyword extends. For example: public class MyClass {} <- this class is implicitly derived from Object, you don't need to write it. If you derive your class from another class, you make this by using the keyword extends For example: public class MyDerivedClass extends MyClass {} Commented Apr 16, 2015 at 10:43
  • similar question stackoverflow.com/questions/19114997/… Commented Apr 16, 2015 at 10:48
  • @bmargulies, now i request answer my doubt Commented Apr 20, 2015 at 13:15
  • @Jeroen Vannevel now i request answer my doubt Commented Apr 20, 2015 at 13:15

2 Answers 2

6
  • Every class, except for java.lang.Object, extends exactly one class.
  • If you write extends Something, then your class extends Something.
  • If you don't write extends Something, then your class extends java.lang.Object. (the same as if you wrote extends Object)
Sign up to request clarification or add additional context in comments.

4 Comments

Every class, except for java.lang.Object, extends exactly one class means what ..?
@P.JAYASRI One class, as opposed to "one or more classes".
i request you please again answer after reading modified question
@P.JAYASRI Ask a new question.
2

If you don't extend any class, you will still extend Object. If you explicitely extend some class, than you extend just this class, but the extended class will in other turn extend Object by default. This way Object is always in class hierarchy.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.