I created a class with name Object in a package java.lang. In some another package I created Main class. Now in main method of Main class when I write new Main() and put a dot after that I don’t see equals(), wait() etc.. i.e methods of actual Object class.
My question is don’t you think creating an class with name Object(specially with java.lang package) should not be allowed. As Object class is by default inherited by all classes so in my case whatever class I define will automatically inherit my class instead of actual object class because class name and package name of my object class is same as that of actual object class.
This is quite an open-ended question.
Should it be allowed? Why not, if you know what you’re doing, go crazy.
I agree it’s somewhat dangerous theoretically, but I don’t see how someone would do this by mistake. If someone actually wants to redefine the whole Object class for some reason, academical for instance, then he/she can do so at his/her own risk.
No language can fully prevent you from putting an arrow to your own knee.