-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparameterized-constructor.java
More file actions
42 lines (34 loc) · 937 Bytes
/
parameterized-constructor.java
File metadata and controls
42 lines (34 loc) · 937 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
import java.io.*;
class paraconst{
// constructor with one argument-String datatype
paraconst(double value)
{
System.out.println("Constructor with one "
+ "argument - Double: " + value);
}
// constructor with two arguments
paraconst(String name, int age)
{
System.out.println(
"Constructor with two arguments -"
+ " String and Integer : " + name + " " + age);
}
// Constructor with one argument but with different datatype
paraconst(long id)
{
System.out.println(
"Constructor with one argument : "
+ "Long : " + id);
}
}
class Execution{
public static void main(String[] args)
{
// Calling the constructor with one arguments of type 'string'
paraconst pc1 = new paraconst(4.56);
// Calling the constructor with two arguments
paraconst pc2 = new paraconst("Deepak", 19);
// Calling the constructor with one argument of type 'Long'.
paraconst pc3 = new paraconst(54578974);
}
}