File tree 1 file changed +54
-0
lines changed
1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ class person
2
+ {
3
+ int age ;
4
+ double height ;
5
+ double weight ;
6
+ person ()
7
+ {
8
+ System .out .println ("No parameterized constructor" );
9
+ age =0 ;
10
+ height =0.0 ;
11
+ weight =0.0 ;
12
+ }
13
+ person (int age )
14
+ {
15
+ System .out .println ("One Parameter Constructor" );
16
+ this .age =age ;
17
+ height =0.0 ;
18
+ weight =0.0 ;
19
+ }
20
+ person (int age ,double height )
21
+ {
22
+ System .out .println ("Two parameter Constructor" );
23
+ this .age =age ;
24
+ this .height =height ;
25
+ weight =0.0 ;
26
+ }
27
+
28
+ person (int age , double height ,double weight ) {
29
+ System .out .println ("Three parameter Constructor" );
30
+ this .age = age ;
31
+ this .height = height ;
32
+ this .weight = weight ;
33
+ }
34
+ public String toString (){
35
+ return "Age:" +age +"\t Height" +height +"\t Weight" +weight ;
36
+ }
37
+
38
+ }
39
+ public class ConstructorOverloading {
40
+ public static void main (String [] args ) {
41
+ person p1 =new person ();
42
+ System .out .println (p1 );
43
+ person p2 =new person (22 );
44
+ System .out .println (p2 );
45
+
46
+ person p3 =new person (22 ,5 );
47
+ System .out .println (p3 );
48
+
49
+ person p4 =new person (22 ,5 ,65 );
50
+ System .out .println (p4 );
51
+
52
+ }
53
+
54
+ }
You can’t perform that action at this time.
0 commit comments