class Record
{
private String name;
private int age;
private float basic;
Record(){}
Record(String name,int age , double basic)
{
this.name = name;
this.age = age;
this.basic = (float)basic;
}
void print()
{
System.out.printf("\n %-15s %2d %8.2f",name,age,basic);
}
public String toString()
{
// return name+" "+age+" "+basic; try removing the comment here & observe the changes
String s = String.format("%-15s %2d %8.2f",name,age,basic);
return s;
}
}
class Main
{
public static void main(String arg[])
{
Record r1,r2;
r1=new Record("vivek warde",20,3800.75);
r2=new Record("kapil",21,3535.55);
r1.print();
r2.print();
System.out.println("\n");
System.out.println("\n r1 : "+r1);
System.out.println("\n r2 : "+r2);
}
}
{
private String name;
private int age;
private float basic;
Record(){}
Record(String name,int age , double basic)
{
this.name = name;
this.age = age;
this.basic = (float)basic;
}
void print()
{
System.out.printf("\n %-15s %2d %8.2f",name,age,basic);
}
public String toString()
{
// return name+" "+age+" "+basic; try removing the comment here & observe the changes
String s = String.format("%-15s %2d %8.2f",name,age,basic);
return s;
}
}
class Main
{
public static void main(String arg[])
{
Record r1,r2;
r1=new Record("vivek warde",20,3800.75);
r2=new Record("kapil",21,3535.55);
r1.print();
r2.print();
System.out.println("\n");
System.out.println("\n r1 : "+r1);
System.out.println("\n r2 : "+r2);
}
}
No comments:
Post a Comment