The Artima Developer Community
Sponsored Link

Java Answers Forum
How come "extends Object" is not required?

3 replies on 1 page. Most recent reply: Mar 18, 2004 12:56 PM by Scuba Steve

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Kevin

Posts: 25
Nickname: doublek321
Registered: Jan, 2004

How come "extends Object" is not required? Posted: Mar 14, 2004 11:15 PM
Reply to this message Reply
Advertisement
I'm guessing it's just inherently there but it's worth asking - When you say something like this...

class MyClass { ... }

how come you don't have to say...

class MyClass extends Object { ... }


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: How come "extends Object" is not required? Posted: Mar 15, 2004 3:09 AM
Reply to this message Reply
This is because every class extends Object.

java.lang.Object
|
+java.lang.Class

Now if u have class structure say.

Now if u create a class it automatically extends Object.

twc

Posts: 129
Nickname: twc
Registered: Feb, 2004

Re: How come "extends Object" is not required? Posted: Mar 15, 2004 5:44 AM
Reply to this message Reply
> I'm guessing it's just inherently there but it's worth
> asking - When you say something like this...
>
> class MyClass { ... }
>
> how come you don't have to say...
>
> class MyClass extends Object { ... }

Yes, it is inherently there. If you don't explicitly extend a class, then the compiler will treat the code as if it automatically extends the Object class. It is kind of like an exponent on a variable in Algebra. If none is written, the variable is considered to be to the first power.

In a related situation, the import statement for the java.lang package is implicit. You never see
import java.lang.*;
because the designers felt that the classes in that package were so vital that every class would need to import that package.

Scuba Steve

Posts: 4
Nickname: scubasteve
Registered: Jul, 2003

Re: How come "extends Object" is not required? Posted: Mar 18, 2004 12:56 PM
Reply to this message Reply
What he said :-)

which is why an object of your class has access to the inherent properties of Object.

Flat View: This topic has 3 replies on 1 page
Topic: HELP! Granting Permission to an applet in a JSP Previous Topic   Next Topic Topic: Calling java.exe using Runtime.getRuntime().exec()

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use