Friday, 21 October 2016

Write a java Program for Construstor Overloading


import java.util.*;
class Cricketer
{
  String name,team;
  int age;
  Cricketer()
 {
   name="";
   team="";
   age=0;
 }
 Cricketer(String n,String t,int a)
 {
    name=n;
    team=t;
    age=a;
 }

 Cricketer(Cricketer ckt)
 {
      name=ckt.name;
      team=ckt.team;
      age=ckt.age;
 }

 public String toString()
 {
   return "This is" + name + "of" +team;
 }

public static void main(String args[])
{
  Cricketer c1 = new Cricketer();

  Cricketer c2 = new Cricketer("VIRAT","INDIA",27);

  Cricketer c3 = new Cricketer(c2);

System.out.println(c2);
System.out.println(c3);
c1.name="Dhoni";
c1.team="INDIA";
c1.age=35;
System.out.println(c1);
}
}

Posts You May Like

loading...

No comments:

Post a Comment