Reference Static Methods/Variables in Java from an Instance

后端 未结 5 1164
傲寒
傲寒 2020-12-11 20:17

Can anyone explain to me why java allows you to access static methods and members from an instance? A bad example, if I have a class called RedShape and it has a static meth

5条回答
  •  没有蜡笔的小新
    2020-12-11 20:43

    The access to static methods allows you to share values between instances of the same class or even get the values without needed to create a class instance.

    There are cases where it's convenient and is no OO language violation.

提交回复
热议问题