0
public class review{
        //method code
        public void start() {
        int a, b;
        a = 5;
        b = methodA(a);
        System.out.println(a + " " + b);
        }

           private int methodA(int a) {
           int b = 10;
           a = a + 5;
           return a + b;
           }
        //method end
    }  

------------------------------------------------
i compile and run this code in dr.java compiler jdk 6.0_41
it can compile, but when i run it will display like thi
"Static Error: This class does not have a static void main method accepting String[]"

when i try to add

public static void main (String[]args){
//method code
}

when i compile it will display

public void start() {

as an illegal start of expression.
it is something wrong with my dr.java compiler or i wrote wrong code?

hope anyone can help.
thanks in advanced

3
Contributors
4
Replies
29
Views
3 Years
Discussion Span
Last Post by somjit{}
1

main is special since it has to be present to start the program, so it's required to have a fixed signature. Under the hood, the java runtime looks for the magic signature to start the program. The magic signature is

public static void main(String[] args)
So your code must look something like this

 public class review{
        //method code
    public void start() {
       //your start() method
        }

            private int methodA(int a) {
      //your methodA
       }
        public static void main (String[]args){
        //create object of review and call start() method using that object.eg:- review referenceVariable = new review();referenceVariable.start();
         }
    }  

Edited by IIM

0

though not related to the problem (which IIM solves above) , but , you should update your java version.
A lot of nasty things are roaming all over cyberspace , each new update helps in making the holes a bit smaller for them to enter your system through.

Edited by somjit{}

0

@somjit : nothing problem with the compiler bro.
@IIM : thanks lot, yah i forgot to put object.

0

the compiler will work fine. but it exposes you to a lot of stuff out there you wouldnt want your machine to be visited by.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.