-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructors.java
More file actions
37 lines (33 loc) · 889 Bytes
/
Constructors.java
File metadata and controls
37 lines (33 loc) · 889 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
/*
In Contructor overloading, multiple contructors with
different number and type of parameters are present.
Return type does have to be mentioned.
All the contructors have same name as their class.
*/
import java.util.*;
public class Constructors
{
Constructors()
{
int x = 35;
int y = 65;
System.out.println("Default Constructor");
System.out.println("First Constructor: " + (x+y));
}
Constructors(int x, int y)
{
System.out.println("Parameterized Constructor");
System.out.println("Constructor Overloading occurs ");
System.out.println("Second Constructor: " + (x+y));
}
Constructors (double x, double y, double z)
{
System.out.println("Third Constructor: " + (x+y+z));
}
public static void main(String[] args)
{
Constructors c = new Constructors();
Constructors c1 = new Constructors(6,5);
Constructors c2 = new Constructors(4.6,9.8,7.2);
}
}