Question by abhay: java and main() return that returns an integer?
is that necessary to do this ??
public static void main()
can we do like this ;
public static int main()
what we have to add in it
/*this is a simple java program*/
class example
{
public static int main(String args[])
{
System.out.println(“this is simple java program”);
return 1;
}
}
produces error –> exception in thread “main” java.lang.NoSuch MethodError: main
i want to make this program with a main() that returns an integer.
i want to make this program with a main() that returns an integer.
i want to make this program with a main() that returns an integer.
Best answer:
Answer by Vineet
May be it should be like this….
class Demo
{
public static void main(String[] args)
{
System.out.println(“Hello World!”);
}
}
Add your own answer in the comments!
In C++ the main() returns a result. Not so in Java.
class Example {
public static void main( String[] args ) {
int x = new Example().intro();
}
private int intro() {
System.out.println(“Whipity bang bang”);
return 1;
}
}
=================
OK, you MUST create an Object to gain method()s, states and values, thus the reason that this main immediately invokes ‘new’ — which puts the Object on the heap and calls a method.
public static void main ( String[] args )
is required and reserved for the Java Runtime Engine. notice it says ‘void’