Created
September 20, 2015 16:20
-
-
Save smamran/a2d8fceab0c49b3a8128 to your computer and use it in GitHub Desktop.
Java Default Constructor vs Parameterised Constructor
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
class Main { | |
public static void main(String[] args) { | |
Person person = new Person(); // will get error as defautl empty constructor is not given | |
} | |
} | |
class Person { | |
String firstName; | |
String lastName; | |
int age; | |
public Person(String f, String l, int a) { | |
firstName = f; | |
lastName = l; | |
age = a; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment