Can someone explain to me why java allows you to access static methods and members from an instance? Bad example, if I have an object called RedShape and it has a static method called getColor () that returns “red”, why does Java allow you to call a static method from an instance of RedShape? For me, this seems to violate some of the basic concepts of OO language design. At least it should appear with a compiler warning.
Thanks in advance.
Edit:
In particular, I ask when you have something like
RedShape test = new RedShape();
test.getColor();
where getColor is a static method of the RedShape class. It makes no sense that it is allowed and does not give a compiler warning on the command line via javac. I see that it was “very discouraged,” but it was curious if there was a technical or reasonable reason why it was allowed outside “because C ++ allows it”.
source
share