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

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;
} }

2 Responses to "How to print some statement to the console without using main()::::Google Interview Question----FAQ"

  1. gravatar mallesh says:

    How you got this question??

  2. gravatar Unknown says:

    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.

Leave a Reply

If you need dumps mail us at javasnips@gmail.com, if you are commenting any other details, your Comment will be posted after approval

Visitor Count

hit counter