I know this fact that main() method is for starting point of programme which is defined by technology.But still we can do entire thing without main method any without any error.
I have this code
public class WithoutMain {
int x=10;
int y=20;
void show() {
System.out.println(x);
System.out.println(y);
}
static {
WithoutMain t=new WithoutMain();
t.show();
System.exit(0);
}
}
I can write this programme without main method, so why is it necessary to have a main method?
you can run program without
main()but you cant runexeorjarfile without entry point.the main method is the default entry point for a programme,you can run independently jar files.
If you’re not trying to produce a programme that needs launching independently, you won’t need it – for example, a jar referenced by other programmes, or a website.
by help of this
main()you can pass arguments