1
package fd;

public class Fd {
    void f(){
        System.out.println("f method is called");
    }
}

class j {
    public static void main(String[] args){
        Fd a=new Fd();
        a.f();
    }
}

The above program can be executed in the Netbeans IDE but when the same program is compiled in Eclipse an error occurs saying

Error: Main method not found in class fd.Fd, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application

So I was wondering if this gotta do with the IDE on which that am running on or is there something else like if its mandatory for putting the main method in public class that linked to the package name.

The above program should be written like the one below in order to get it executed in Eclipse:

package fd;

public class Fd {
    public static void main(String[] args){
        j a=new j();
        a.f();
     }  
}

class j{
    void f(){
        System.out.println("f method is called");
    }
}
aUserHimself
  • 1,589
  • 2
  • 17
  • 26
  • 2
    Duplicate of https://stackoverflow.com/questions/12524322/what-if-main-method-is-inside-non-public-class-of-java-file ? – M. le Rutte Oct 05 '17 at 14:25
  • It can depend on how the application is launched. The safest option is to make it a public class. – Peter Lawrey Oct 05 '17 at 14:42
  • 1
    Possible duplicate of [What if main method is inside "non public class" of java file?](https://stackoverflow.com/questions/12524322/what-if-main-method-is-inside-non-public-class-of-java-file) – HaveSpacesuit Oct 05 '17 at 14:54

0 Answers0