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???????
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
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(); } }
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!
Ads