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 :-)