Last active
January 3, 2016 18:28
-
-
Save rajeevprasanna/8502002 to your computer and use it in GitHub Desktop.
constructor chaining
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int constant; | |
private Bar(){ | |
//System.out.println("tewsts"); | |
//this(5); | |
System.out.println("default constructor is called"); | |
} | |
private static boolean instanceAvailable; | |
private static Bar bar; | |
public static Bar getInstance() { | |
if (!instanceAvailable) { | |
bar = new Bar(); | |
instanceAvailable = true; | |
} | |
return bar; | |
} | |
public void test(){ | |
} | |
public static void main(String[] args){ | |
//Bar b = new Bar(5); | |
//b.test(); | |
// output : | |
//abstract Foo class constructor is invoked | |
//Bar constructor is invoked | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package constructors.constructorChaining; | |
public abstract class Foo { | |
public Foo(){ | |
System.out.println("abstract Foo class constructor is invoked"); | |
} | |
public abstract void test(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment