Error in Sample questions from Oracle

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
deepa.patre
Posts: 15
Joined: Thu Dec 13, 2012 9:44 am
Contact:

Error in Sample questions from Oracle

Post by deepa.patre »

Here is the code

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";
	}
	}
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.

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Error in Sample questions from Oracle

Post by admin »

1. all methods of an interface are public even if you don't write public keyword in front of the methods. So that is why if you don't make the method public in the class, it fails to compile.

2. Not sure what and how exactly are you running the code but there is no problem with the main method that you've shown here.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

deepa.patre
Posts: 15
Joined: Thu Dec 13, 2012 9:44 am
Contact:

Re: Error in Sample questions from Oracle

Post by deepa.patre »

Thanks! The program is executing...

Post Reply

Who is online

Users browsing this forum: No registered users and 262 guests