Why can I create a class named Object and then compile and run a program with it?

George McKinney

I assume you are creating an Object in the unnamed package. In that case your Object will be a subclass of java.lang.Object, and it's perfectly fine to create such a class. But (I suspect, but haven't tested) any time your program wants to refer to the "official" Object, you'll have to use "java.lang.Object". Because the names of all the classes in java.lang are imported automatically, there will be a name conflict.

You can do it, but it would be a bad idea :-)

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact