- 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
4 odpowiedzi
+ 3
You cannot override a static method.
Anywho, can you show us the code? Your question doesn't make sense.
+ 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)
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.
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.