Types of Java Constructor and its usage
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
/** * */ package defaultConstructorCallAfterCreatingMultiOBJ; /** * @author Kushal Thadani * */ public class DefaultConstructor { int id; int ids; int count; String emp_name ; String designation; float salary; DefaultConstructor(){ ids =1012; } DefaultConstructor(int id){ this.id =1; } DefaultConstructor(int count , String emp_name){ this.id =10; this.emp_name = "Kushal Thadani"; } DefaultConstructor(int count , String emp_name , float salary){ this.id =10; this.emp_name = "Kushal Thadani"; this.salary = 1200000.00f; } DefaultConstructor(int count, String emp_name ,float salary , String designation){ this.count = count; this.emp_name =emp_name; this.salary = salary; this.designation = designation; } void m() { System.out.println(ids); } void m1() { System.out.println(id + "\t" +emp_name + "\t" + salary); } void m3() { System.out.println(count + "\t" + emp_name + "\t" + salary + "\t" +designation); } public static void main(String[] args) { DefaultConstructor t = new DefaultConstructor(); DefaultConstructor t1 = new DefaultConstructor(10 , "Parameter Constructor" , 1200000.00f); DefaultConstructor t2 = new DefaultConstructor(112 , "Kushal Thadani" , 102300.54f , "Developer"); DefaultConstructor t3 = new DefaultConstructor(1123 , "Rahul Shah" , 50400.90f , "Designer"); t.m(); t1.m1(); t2.m3(); t3.m3(); } } |