- 1

Is it legal to use static when defining the subclasses for a polymorphism method.

I am trying to run the example given in net bean but it's brining the error that non static variable

15th May 2017, 8:07 PM
Paul Mutondo
Paul Mutondo - avatar
4 odpowiedzi
+ 3
You cannot override a static method. Anywho, can you show us the code? Your question doesn't make sense.
15th May 2017, 9:00 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
I assume the issue is that you don't have a public class, so netbeans can't figure out which class has the main method. Since all these classes are in a single file. So, try writing: public class Program{ } (let me know if I'm wrong, this is just speculation)
15th May 2017, 10:31 PM
Rrestoring faith
Rrestoring faith - avatar
0
I'm not sure what you mean by "subclass of a polymorphic method". When you override a method a in a subclass (<- this way round) you can theoretically override static methods, too. Unless they were final of course. But you cannot override an instance method with a static one or vice versa.
15th May 2017, 8:15 PM
1of3
1of3 - avatar
0
https://code.sololearn.com/cS5M7t1Nfiat/?ref=app The above link contains a code which is one of the examples​ on polymorphism in java. now I tried to use the same syntax in NetBeans but gave an error stating that main method not found in class Animal. what could be problem? sorry for the unclear question in the first place. if it is still not clear I can refrase the question.
15th May 2017, 10:12 PM
Paul Mutondo
Paul Mutondo - avatar