hi all
As we know static methods are never Overridden. Rather they are just redefined.
However I noticed something I could not understand.
If the eat method in
Fruit class is just a redefined method and not an Override,
how come compiler complains with this error:
D:\Java Programs>javac Food.java
Food.java:7: eat() in Fruit cannot override eat() in Food; attempting to assign
weaker access privileges; was public
private static void eat(){
^
1 error
Does that mean the Rules of Overriding apply here?
I also tried other violations of the rules and each result in an error related to Overriding.
One more thing,
when i removed static modifier from one of the methods, It also results in an error that too related to Overriding.
D:\Java Programs>javac Food.java
Food.java:7: eat() in Fruit cannot override eat() in Food; overridden method is static
private static void eat(){
^
1 error
please help.