Java
Programming and Technical
Programming
Program
Q. Can we execute a java program without main() method ?
Read Solution (Total 18)
-
- It depends upon the java version we are using.If we are using java 6,then by using the static block,we can execute a program without a main().But in java 7,even if we use static block,there should me main() compulsorily or else JVM will throw an exception-"java.lang.NoSuchMethodError:main"
- 10 years agoHelpfull: Yes(26) No(0)
- yes,it is possible by usung a static initializer block.for eg.,
public class Gkcem {
static {
System.out.println("Avijit Gkcem");
}
} - 11 years agoHelpfull: Yes(8) No(3)
- it is possible upto java 6.but in java 7 it shows error message.so, static block can't be executed without main() method.
- 10 years agoHelpfull: Yes(2) No(0)
- no we cannot execute java with out main() but we can compile
- 10 years agoHelpfull: Yes(2) No(1)
- Yes...it is possile by using Static blocks.
- 10 years agoHelpfull: Yes(1) No(0)
- it can not be executed.when we use static block it will compile but can not run.it will show runtime error(main() method not found).
- 10 years agoHelpfull: Yes(1) No(0)
- Yes, it's possible. If a static method is present.
bcoz static method is executed before execution of the main() method. - 11 years agoHelpfull: Yes(0) No(0)
- yes.we can execute a java program without main()method using static method.Static method will occupy the memory .
- 10 years agoHelpfull: Yes(0) No(0)
- Ya its 100% possible depends on the version of JDK below 1.5(means jdk
- 10 years agoHelpfull: Yes(0) No(0)
- we can execute output also display bt after output it will display "exception thread in main"
- 10 years agoHelpfull: Yes(0) No(0)
- no
because every java program compile first with main method only - 10 years agoHelpfull: Yes(0) No(1)
- yes we can execute the program without main method by using static block
- 10 years agoHelpfull: Yes(0) No(0)
- java program cannot compile without main().....
answer is.....NO - 10 years agoHelpfull: Yes(0) No(1)
- by using static
static{
System.out.println("hi");
} - 10 years agoHelpfull: Yes(0) No(0)
- from java 7 version onwards we can not execute. using before versions can be executed using static block.
- 9 years agoHelpfull: Yes(0) No(0)
- double can hold max values after decimal..so option d
- 9 years agoHelpfull: Yes(0) No(0)
- before 1.7 version possible after 1.7 without main() method it can not be possible
- 8 years agoHelpfull: Yes(0) No(0)
- yes...
using static... - 8 years agoHelpfull: Yes(0) No(0)
Java Other Question