-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConstructorOver.java
More file actions
40 lines (33 loc) · 953 Bytes
/
ConstructorOver.java
File metadata and controls
40 lines (33 loc) · 953 Bytes
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
public class ConstructorOver {
int num;
int num1;
String var;
ConstructorOver(int no,String variable){
num = no;
var = variable;
}
// Constructor Overloading
ConstructorOver(int no,String variable,int no1){
num = no;
var = variable;
num1 = no1;
}
ConstructorOver(int no,int no1){
num = no;
num1 = no1;
}
// Method
void display(){
System.out.println(var + ": " + num + " and " + num1);
}
public static void main(String[] args) {
ConstructorOver obj = new ConstructorOver(5,"Value");
ConstructorOver obj1 = new ConstructorOver(5,"Values",10);
ConstructorOver obj2 = new ConstructorOver(5,10);
// if any integer value is not present then it will be "0"
obj.display();
obj1.display();
// if any string is not present then it will show "null"
obj2.display();
}
}