Code academy exercice

error error: cannot find symbol
symbol: variable feet
location: class Droid
1 error


Haven’t done this exercise yet, but you have no variable called ‘feet’ in the main method. You must either create an int variable called feet, or pass in an integer for the function to use.

hi yes i have finished the exercise as indicated in the links the code is complete just the error is present i do not know what to do

Hmm, look at your main method:

public static void main (String[] args ){
    Droid myDroid = new Droid();

Java can’t figure out what value feet is referring to in the last line where you call myDroid.hover(feet). This is because there’s no variable in here called feet. Does that make sense?

1 Like

int feet is created l32 public void hover (int feet){

Ah I see. So you need to note the difference between those two functions.

First of all, functions do not share variables (unless they are nested, but here they are not). It’s because they all have different scopes, or their own “environments” where variables live. The environment for public static void main is not the same as public void hover, which is why you can’t use the feet from hover in main.

Instead, you need to create your own variable called feet in main that holds the value you want to use. Hopefully that makes sense :grimacing:.

This is about parameters and arguments.

when you declare a method:

public void hover (int feet)

you give the method a parameter (feet).

then when you call the method:


You need to provide an argument for the parameter. In this case, the arguments need to be a integer, so you can pass an integer directly:


or you can first declare a variable:

int hoverDistance = 6

then Java will “assign” the argument(s) to the parameter(s)

furthermore, parameters do indeed have a local scope, so feet only exist within the hover method.

thanks for your reponse :slight_smile: