You are here:   HomeJava ProgrammingClasses in JavaPass by Value and Pass by Reference in Java Example
by Dinesh Thakur Category: Classes

 

        class Worker

           {
               int code, sal;
               String nme;
               Worker()
                  {
                     code=1;
                     nme="Anil";
                     sal=4200;
                  }
                    Worker(int x, String y)
                       {
                          code=x;
                          nme=y;
                          sal=600;
                       }
                          Worker(int x, String y,  int z)
                            {
                               code=x;
                               nme=y;
                               sal=z;
                            }
                               void ShowDetail()
                                  {
                                       System.out.println("Employee Code :"+code);
                                       System.out.println("Employee Salary :"+sal);
                                  }
            };
                  class WorkerConstructorOverloading
                     {
                         public static void main(String args[])
                            {
                                Worker WorkerDetail = new Worker();
                                Worker WorkerDetail1 = new Worker(1,"Geeta");
                                Worker WorkerDetail2 = new Worker(2, "Kumar", 90000);
                                WorkerDetail.ShowDetail();
                                WorkerDetail1.ShowDetail();
                                WorkerDetail2.ShowDetail();
                            }
                    };

Detail of Worker using Constructor Overloading

What's New and Popular