how to print a message to console without using main()
function?(do not use even static blocks also.)
Answers were Sorted based on User's Feedback
Answer / ravi kumar
No method can be called with out using main() method.
Every program execution starts from main() method only.
even you declare the methods inside the main() method class or out side the main() method class.
| Is This Answer Correct ? | 1 Yes | 6 No |
Answer / gaurav
with use of main we can print message in cosole by the use
of static block because java provide class loading machanism
i n program ,
Example-
class A
{
static
{
System.out.println("execute with out use of main");
System.exit(0);
}
}
| Is This Answer Correct ? | 1 Yes | 6 No |
Answer / jaya
public class classWithoutMain {
private static int x = load();
private static int load() {
System.err.println("This message will be printed");
System.exit(0);
}
}
| Is This Answer Correct ? | 2 Yes | 8 No |
Answer / narender
using a static block you can print the message (string)s.o.p
| Is This Answer Correct ? | 11 Yes | 29 No |
A game that has five levels of play has the score for each level stored in an array. You are to write a program that goes through that array and finds: a) the minimum score, and the level at which it occurred b) the maximum score, and the level at which it occurred c)the average score for all five levels The score data you must use for this program are as follows: Game Level Score 1 450 2 316 3 148 Stack implementations is mandatory.
How to create Date method to set the date in Ms Access
For printing a message we use System.out.println in normal programs. We use String msg="text....."; Can't we use String msg=" " in normal programs and System.out.println("........") in applets. Please answer this question?
write a program that will ask the user to enter a number n and display the product of all numbers from 1 to n.
write a java program to create a Frame with three scrolls, change the back ground color of the frame using functions with values of scrolls.
How to create and run runnable jar file of a Java Project.
4 Answers HCL, TCS, Tech Mahindra, US Consulate, Wipro,
Can we run Applet in Web browser with security policy files
Write a java program to display multiplication table in a Frame.
Write a program to convert a decimal number to binary form?
write a program in java to find the moving average of all prime numbers between 2 and 100.
Why the program getting error if we don't use String args[] in main(), even in the case of not getting any arguments from command line?
In java, why do we set thread priority, when we know that there is no guarantee by which a thread should be execute?