Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Java method problem please help?

Can someone please tell me why my program won't compile,If I take out the second(); method call from the main method it will work until I insert it again and it gives me errors,am i declaring the method wrong,please help I'm so confused (I've also tried calling "first();" method to no avail.

class ut{

public static void main(String[] args){

second();

}

public void first(){

second(20);

}

public void second(int age){

System.out.print(age);

}

}

3 Answers

Relevance
  • 7 years ago
    Favorite Answer

    Try the following code:

    class ut{

    public static void main(String[] args){

    first();

    }

    public static void first(){

    second(20);

    }

    public static void second(int age){

    System.out.print(age);

    }

    }

    Source(s): Experience
  • djbckr
    Lv 5
    7 years ago

    second is defined with an int parameter. You *must* call it with an int, otherwise it's a compiler error.

  • adel
    Lv 4
    7 years ago

    must be second(30) or some other int in the parameter

Still have questions? Get your answers by asking now.