javaclassinheritancemethodsprogram-entry-point

Why am I getting the error 'Main method not found in class' even though I defined the main method in my Java program with inheritance?


package code.now;


class Test {
    public void fun() {
        System.out.println("Coding Ninjas");
    }
}

class Derived extends Test {
    
    public void fun() {
        System.out.println("Coding Ninjas");
    }
    public static void main(String[] args) {
        Derived obj = new Derived();
        obj.fun();
    }
}

i'm trying to execute this code and running into the below error

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

but I already defined the main method and also tried to check for any syntax and spelling mistakes but still the code is returning the error.


Solution

  • I faced the same before. Your code is good. No issues. Problem with IDE config.

    For Eclipse https://stackoverflow.com/a/75637946/11962586

    UPDATE - Try this way

    enter image description here enter image description here enter image description here