Created
January 19, 2014 08:28
-
-
Save rajeevprasanna/8501958 to your computer and use it in GitHub Desktop.
default constructor explained
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.baseExample; | |
public class Foo { | |
int size; | |
String name; | |
Foo(String name, int size) { | |
this.name = name; | |
this.size = size; | |
} | |
public static void main(String[] args) { | |
//Foo foo = new Foo(); compilation fails as it doesn't have default no-arg constructor | |
Foo foo2 = new Foo("Fred", 43);// No problem. Arguments match the Foo constructor | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment