Skip to content

Instantly share code, notes, and snippets.

@rajeevprasanna
Created January 19, 2014 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajeevprasanna/8501958 to your computer and use it in GitHub Desktop.
Save rajeevprasanna/8501958 to your computer and use it in GitHub Desktop.
default constructor explained
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