Object class is the member of java.lang package which is implictly imported in every source file.
consider the following code:
This code compiles and runs fine.
I want to know that if Object class is already present in the current scope how are we able to redeclare it.
Also JLS states that :
The extends clause must not appear in the definition of the class Object, because it is the primordial class and has no direct superclass.
Then how are we able to extend the thread class in the above mentioned code?
Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Doesnt java.lang package already imported in each and every source file. and if it is then ofcourse all of its compilation units are also there. then why writing : import java.lang.Object; gives error?
java,lang - It is imported explicitly but can be overriden with one's own class name . Explicitly writing an import java.lang.Object causes ambiguity - because the compiler does not know which <ClassName> to substitute with full package name [java.lang...] and which is is customized [myPackage.Object]
Joined: Aug 28, 2005
Thanx for your replies
This is an abstract from JLS Ch-7
A package consists of a number of compilation units (�7.3). A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang.
According to this class java.lang.Object is automatically imporeted in our source file. if i dont declare the statement: import java.lang.Object; even though it is being automatically imported in the source file Then why there is not ambiguity in that case?