0

I was going through some basic java concepts. I was looking into methods and trying to verify this error

"MethodSignature.java:10: error: method m1(String) is already defined in class MethodSignature
        public static void m1(String s)"

The above error appears when I run from command prompt. But when running through eclipse, although it shows error, program prints the desired strings. I do not get any error as stated above in case of command prompt.

Why there is a difference in execution in Eclipse and command prompt?

As in command prompt, I am not able to run the program itself because the error should stop me. I was expecting the same in Eclipse.

Here is my simple program.

public static void m1(String s)
{
    System.out.println(s);
}

public static void m1(String s)
{
    System.out.println(s);
}


public static void main(String[] args)
{       
    m1("call one");

    m1("call two");



}
edkeveked
  • 17,989
  • 10
  • 55
  • 93

1 Answers1

0

You must be running a previously compiled class, you cannot declare m1 twice. However, eclipse does have its' own compiler (ecj); and it is possible to run code ignoring errors (in which case it removes the invalid code for you).

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249