Error: please define the main method as: public static void main(String args)

While Executing below program I'm getting error message as "Error: Main method not found in class Parent_Package.Parent, please define the main method as: public static void main(String[] args)".................. Can any one know how to resolve this??

First Package
package Parent_Package;

public class Parent {
     int money = 100;enter code here
     protected  void give_Money(){
    money = money-10;

Second Package
 package Child_Package;

 import Parent_Package.Parent;

 class Child extends Parent{
        public void donate() {


 class Friend {
     public static void main(String[] args){
    Child c = new Child();


4 Answers
  1. When running this Java program you need to run the Friend class as this is the only one with a main method.

    It looks like you are running the Parent class which does not have a main method defined.

    2013-03-13 10:55:23
  2. The class which has main method should be marked as public.

    So, make your class Friend as public class Friend


    run java Friend instead of java Parent

    2013-03-13 10:56:26
  3. By default, running a file with several classes will run the public one (only one can be public in a single file). In your code Parent is the public calss which does not contain a main method. That's why it doesn't find a main method.

    javadev2013-03-13 11:09:38
  4. Since you haven't marked the Parent class as public, the "default" access modifier will be assigned. In java the classes can only see the "public" classes present in another package. Since your Friend is marked default (by compiler), Child class won't be able to see the Parent class.

    Akshay2013-10-10 04:41:04
Related Articles
You Might Also Like