Interviewer: Is it possible to print some statement to the console without using main()? If it is yes...How?
Interviewee: Yes sir,...As follows
class SCJP
{ static
{ System.out.println("SCJP-FAQ");
System.exit(0);
} }
Interviewer: Fine. Then Is it possible to print some statement to the console without using main() and a static block?
Interviewee: Yes sir, No problem at all...As follows
class SCWCD
{ static int i=m1();
public static int m1()
{ System.out.println("SCWCD-FAQ");
System.exit(0);
return 10;
} }
Contact Admin for Dumps and Queries
Just drop a mail to javasnips@gmail.com with subject as "SCJP Dumps" or "SCWCD/SCBCD Dumps".
How to print some statement to the console without using main()::::Google Interview Question----FAQ
You can leave a response.
How you got this question??
You can NEVER print some statement anywhere without invoking main(). All understand the nature of the question here and was immediately able to come up with the answer, however, you have to realize that at some point, the program has to have an entry point, or a main()--even if it's not coded in this particular class (i.e. SCWCD). If there is another class with main() that merely uses SCWCD, then yes, the static block initializer or static class variable are loaded and print is executed. Nonetheless, there must be main() somewhere.