|
| 1 | +class cars |
| 2 | +{ |
| 3 | + public int a; |
| 4 | + public String b; |
| 5 | + public double c; |
| 6 | + |
| 7 | + public cars() |
| 8 | + { |
| 9 | + this(12,"Ajitkumar",23.5); |
| 10 | + } |
| 11 | + |
| 12 | + public cars(int c) |
| 13 | + { |
| 14 | + this(c,"vaghela",12.5); |
| 15 | + } |
| 16 | + |
| 17 | + public cars(int c,String h) |
| 18 | + { |
| 19 | + this(c,h,65.2); |
| 20 | + } |
| 21 | + |
| 22 | + public cars(int x,String y,double z) |
| 23 | + { |
| 24 | + this.a=x; |
| 25 | + this.b=y; |
| 26 | + this.c=z; |
| 27 | + } |
| 28 | +} |
| 29 | +public class conthis { |
| 30 | + |
| 31 | + public static void main(String[] args) |
| 32 | + { |
| 33 | + cars obj1=new cars(); |
| 34 | + |
| 35 | + System.out.println("\nfirst constructor is call\n"); |
| 36 | + System.out.println(obj1.a); |
| 37 | + System.out.println(obj1.b); |
| 38 | + System.out.println(obj1.c); |
| 39 | + |
| 40 | + System.out.println("\nsecond constructor is call\n"); |
| 41 | + |
| 42 | + cars obj2=new cars(14); |
| 43 | + |
| 44 | + System.out.println(obj2.a); |
| 45 | + System.out.println(obj2.b); |
| 46 | + System.out.println(obj2.c); |
| 47 | + |
| 48 | + System.out.println("\nthird constructor is call\n"); |
| 49 | + |
| 50 | + cars obj3=new cars(14,"Annex4u"); |
| 51 | + |
| 52 | + System.out.println(obj3.a); |
| 53 | + System.out.println(obj3.b); |
| 54 | + System.out.println(obj3.c); |
| 55 | + |
| 56 | + System.out.println("\nfourth constructor is call\n"); |
| 57 | + |
| 58 | + cars obj4=new cars(160,"hardik",20.20); |
| 59 | + |
| 60 | + System.out.println(obj4.a); |
| 61 | + System.out.println(obj4.b); |
| 62 | + System.out.println(obj4.c); |
| 63 | + |
| 64 | + |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments