Constructor 161027225521
Constructor 161027225521
Constructor 161027225521
CONSTRUCTO
R IN JAVA
Constructor 2
2. Parameterized constructor
Default constructor 5
id = i;
name = n;
}
111 Karan
222 Aryan
Constructor overloading 9
Like other methods in java constructor can be overloaded i.e. we can create as
many constructors in our class as desired. Number of constructors depends on
the information about attributes of an object we have while creating objects.
example: constructor overloading example:
class Language {
10
String name;
Language() {
Language(String t) {
name = t;
cpp.setName("C++");
java.getName();
cpp.getName();
void setName(String t) {
name = t;
void getName() {
}
Output: 11