Error in Sample questions from Oracle
Posted: Thu Jun 06, 2013 12:14 pm
Here is the code
When i execute this in eclipse it shows the error as - "Cannot reduce the visibility of the inherited method from Rideable" So i made getGait() in Camel as public...
1. But my question is: I haven't reduced the visibility its the same as inherited method then why is the error?
After making the method public when i try to execute it shows the following message - " Exception in thread "main" java.lang.NoSuchMethodError: main"
What is the problem with the code?
How do i make it work?
Please advise,
Regards,
Deepa.
Code: Select all
interface Rideable {
String getGait();
}
public class Camel implements Rideable {
int weight = 2;
public static void main(String[] args) {
new Camel().go(8);
}
void go(int speed) {
++speed;
weight++;
int walkrate = speed * weight;
System.out.print(walkrate + getGait());
}
String getGait() {
return " mph, lope";
}
}
1. But my question is: I haven't reduced the visibility its the same as inherited method then why is the error?
After making the method public when i try to execute it shows the following message - " Exception in thread "main" java.lang.NoSuchMethodError: main"
What is the problem with the code?
How do i make it work?
Please advise,
Regards,
Deepa.