Java
Programming and Technical
Programming
Arrays
how can we print a statement in java with out main method in the java 7 version
Read Solution (Total 12)
-
- class hello
{
static
{
System.out.println("Hello");
}
} - 8 years agoHelpfull: Yes(6) No(3)
- From 1.7 version onwards main() is mendatery to start program execution hence even though class contains static block it won't be executed if the class does not contain main method
let us understand with a example I execute this code in both version( 1.6 and 1.7) and in both version i got diffrent Result
class Test
{
static
{
System.out.println("Static block");
}
}
in 1.6 version ---- javac Test.java
java Test
ouput -
Static block
Runtime exception - no such method error:main
in 1.7 version : javac Test.java
java Test
error : main() not found in class Test
so if any one ask such type of question with mention 7 version you can cndntly say , No sir it is not possible .. - 8 years agoHelpfull: Yes(4) No(0)
- by using static block
- 8 years agoHelpfull: Yes(1) No(1)
- we cannot print a statement in java without main() from java 1.7 onwards. it must contain main().
- 7 years agoHelpfull: Yes(1) No(0)
- with the help of static blocks..
because,at the time of class loading class loader loads all the static members in static pool. - 8 years agoHelpfull: Yes(0) No(1)
- public class Hello{
static{
System.out.println("u r in static block;");
}
public static void main(String[] args) {
}
} - 8 years agoHelpfull: Yes(0) No(3)
- class S
{
static{
System.out.println("Hello world");
}
public static void main(String args[])
{
//there must be main function as java compiler search for main function first.
}
} - 8 years agoHelpfull: Yes(0) No(2)
- by using static block
- 8 years agoHelpfull: Yes(0) No(1)
- By using Static block
- 8 years agoHelpfull: Yes(0) No(1)
- No java is not pure object oriented..as there are primitive data types which are also defined
- 7 years agoHelpfull: Yes(0) No(0)
- e cannot print a statement in java without main() from java 1.7 onwards. it must contain main() method
othewise it will gives exception main() method does not found - 6 years agoHelpfull: Yes(0) No(0)
- class hello
{
static
{
System.out.println("Hello");
}
} - 5 years agoHelpfull: Yes(0) No(1)
Java Other Question