-
Notifications
You must be signed in to change notification settings - Fork 11
/
TypeOfConstructor.java
44 lines (32 loc) · 1.03 KB
/
TypeOfConstructor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package assignment_3;
class constructor{
//creating a default constructor
constructor(){
System.out.println("constructor is created");
}
int id;
String name;
//creating a parameterized constructor
constructor(int i,String n){
id = i;
name = n;
}
//method to display the values
void display(){System.out.println(id+" "+name);
}
}
public class TypeOfConstructors {
//main method
public static void main(String[] args) {
System.out.println("this is the default constructor");
constructor c = new constructor();
System.out.println("--------------------------------------------");
System.out.println("this is parametrised constructor");
constructor s1 = new constructor(202052343,"vaibhav gupta");
constructor s2 = new constructor(202051000,"default");
//calling method to display the values of object
s1.display();
s2.display();
System.out.println("---------------------------------------------");
}
}