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.

Community
  • 1
  • 1
P.JAYASRI
  • 358
  • 2
  • 18
  • 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 {}` – WrongRhyme Apr 16 '15 at 10:43
  • similar question http://stackoverflow.com/questions/19114997/why-does-every-object-in-java-implicitly-extend-java-lang-object-class – codeMan Apr 16 '15 at 10:48
  • @bmargulies, now i request answer my doubt – P.JAYASRI Apr 20 '15 at 13:15
  • @Jeroen Vannevel now i request answer my doubt – P.JAYASRI Apr 20 '15 at 13:15

2 Answers2

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)
user253751
  • 57,427
  • 7
  • 48
  • 90
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.

makasprzak
  • 5,082
  • 3
  • 30
  • 49