Skip to main content
added 5 characters in body
Source Link
Chetan Kinger
  • 15.2k
  • 6
  • 53
  • 86

A static and non static method can't have the same namesignature in the same class. This is because you can access both a static and non static method using a reference and the compiler will not be able to decide whether you mean to call the static method or the non static method.

Consider the following code for example :

Ov ov = new Ov(); ov.fun(); //compiler doesn't know whether to call the static or the non static fun method. 

The reason why Java may allow a static method to be called using a reference is to allow developers to change a static method to a non static method seamlessly.

A static and non static method can't have the same name in the same class. This is because you can access both a static and non static method using a reference and the compiler will not be able to decide whether you mean to call the static method or the non static method.

Consider the following code for example :

Ov ov = new Ov(); ov.fun(); //compiler doesn't know whether to call the static or the non static fun method. 

The reason why Java may allow a static method to be called using a reference is to allow developers to change a static method to a non static method seamlessly.

A static and non static method can't have the same signature in the same class. This is because you can access both a static and non static method using a reference and the compiler will not be able to decide whether you mean to call the static method or the non static method.

Consider the following code for example :

Ov ov = new Ov(); ov.fun(); //compiler doesn't know whether to call the static or the non static fun method. 

The reason why Java may allow a static method to be called using a reference is to allow developers to change a static method to a non static method seamlessly.

Source Link
Chetan Kinger
  • 15.2k
  • 6
  • 53
  • 86

A static and non static method can't have the same name in the same class. This is because you can access both a static and non static method using a reference and the compiler will not be able to decide whether you mean to call the static method or the non static method.

Consider the following code for example :

Ov ov = new Ov(); ov.fun(); //compiler doesn't know whether to call the static or the non static fun method. 

The reason why Java may allow a static method to be called using a reference is to allow developers to change a static method to a non static method seamlessly.