Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Tricky use of static initializer in Java - Override println

Can we get a different Output without changing the main-method definition?public class HelloMain {/*** @param args*/public Static void main(String[] args) { System.out.println("Mr. main.");}}Can we have the output of the above code-segment as "Hi, Mr. main. Bye!" without changing the main-method code?Yeah, we can have the required output by using 'static initializer' blocks effectively. As we



This post first appeared on Geek Explains: Java, J2EE, Oracle, Puzzles, And Problem Solving!, please read the originial post: here

Share the post

Tricky use of static initializer in Java - Override println

×

Subscribe to Geek Explains: Java, J2ee, Oracle, Puzzles, And Problem Solving!

Get updates delivered right to your inbox!

Thank you for your subscription

×