class Sample {int a; { System.out.println("Inside Non-static/Instance block"); a=100; } Sample() { System.out.println("Inside Constructors"+ a); a = 2000; System.out.println("Hello World!"+a); } Sample(boolean x) { System.out.println("Inside Constru"+a); a=3000; System.out.println("Hello World!"+a); } public static void main(String[] args) { System.out.println("Start"); Sample s1 = new Sample(); Sample s2 = new Sample(true); System.out.println("Stop"); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter