Display Hello even before main get executed??

Display Hello even before main get executed??

I have a class (main method) as follow.....As I know this can be done using static method, but Q is how?

**class Hello{ public static void main(String[] args){ System.out.println("Darling"); } }**

I want result as Hello! Thank you!! when I run the program.

Please assist???????

View Answers

March 15, 2011 at 6:06 PM

class Hell { static { System.out.println("Hello, Thank You"); }

public static void main(String[] args) { System.out.println("Darling"); }

}

I used here static block try it


March 16, 2011 at 2:28 PM

class Hello{
    static void display(){
        System.out.print("Hello ");
    }
    static void show(){
        System.out.print(", Thank you");
    }
    public static void main(String[] args){
        display();
        System.out.print("India");
        show();
        }
        }

March 17, 2011 at 3:49 PM

Thank you for your prompt and quick reply....

I got the required output with below code.

public class Test1 { public static void main(String[] args) { System.out.print("Darling, "); }

static
    {
    System.out.print("Hello ");
    main(null);
    System.out.println("Thank You! ");
    System.exit(0);
}

}

Output: Hello Darling, Thank you!









Related Tutorials/Questions & Answers:
Display Hello even before main get executed??
Simple Procedure to display Hello World
Advertisements
Get and Display using JOptionPane
hello
hello
hello
hello
Hello ..
get and display blob from mysql on jsf
odd and even
Hello
hello
say hello in spanish
Display "Hello JSP" using Jsp expression
ZF Hello World
MAin error
display
Even and odd functions in java
Check even or odd number.
main method
Dojo Hello World
Writing Hello World
EVEN NUMBERS - Java Interview Questions
how to get the data from database&how to display the database data in jsf - Java Server Faces Questions
settings in control panel before jdbc
Flex 4 Hello World
Hello World iphone Example
convertion before downloading
validate parameter before using it
Hello world program
main method
main method
rename before uploading
hello in vertical manner
main function
main() method
ModuleNotFoundError: No module named 'even_detector'
ModuleNotFoundError: No module named 'even_detector'
ModuleNotFoundError: No module named 'even-tester'
Odd Even Transposition Sort In Java
main() syntax - Java Beginners
Hello Eyeryone...
Hello world
Printing the integers before and after - JSP-Servlet
print the even numbers between the range 100-200
even more circles - Java Beginners
main method
Simple Procedure to display Hello World
Displaying Hello using RMI
Is main method compulsory in Java?

Ads