I'm doing an assignment for a class and I can't figure out what I'm doing wrong to keep getting the "illegal start of expression" error. Any help would be appreciated.

public class Overloading {
 public static void main(String[] args) {

 public static int max(int num1, int num2) {
  if (num1 > num2)
   return num1;
  else
   return num2;
  }

  public static double max(double num1, double num2) {
   if (num1 > num2)
    return num1;
   else
    return num2;
   }

  public static int max(double num1, double num2) {
   if (num1 > num2)
    return num1;
   else
    return num2;
   {

  public static double max(int num1, double num2) {
   if (num1 > num2)
    return num1;
   else
    return num2;
  }
}

Recommended Answers

All 5 Replies

You can't define a method inside another method.

ps: next time post the complete error message with line numbers etc

Look at line 23. You have the wrong brace there. Should be }

As stated by DeBlanc, line 23, but there are also missing curly braces } at the bottom.

I think you are missing one curly brace at the bottom as well.

Todd

Yep, flip the brace at line 23 and add another brace at the bottom, too - for starters. That will make it at least marginally make sense. It would be useful to know what language this was supposed to be in, too, because the initial note by James - you can't define a function inside a function definition - has merit, too - although there may be languages where that restriction doesn't apply in some cases. But in Java or C or C++ or C# you kinnae do that. This is also an excellent example of why I don't like the OTB style - it is far too easy to make mistakes like this in OTB and it hasn't served a useful purpose in two decades.

Yeah. The OP was tagged "java", so that's clear enough.
The bracketing style, regardless of what you call it or how you feel about it, is consistent with that used throughout java itself (language reference, offical tutorials, API source code), so it's as de-facto a standard as anything can be.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.