Saturday, 3 September 2011

Composition of Two Classes in java


class orange
{
private int day;
private int mounth;
private int year;

public orange(int d, int m, int y)
{
day=d;
mounth=m;
year=y;
System.out.printf("object has been initialized with value %s\n",this);
}
public String toString()
{
return String.format("%d/%d/%d",day, mounth, year);
}

}



public class banana
{
private String name;
private orange birthday;

public banana(String theName, orange theDate)
{
name=theName;
birthday=theDate;
}
public String toString()
{
return String.format("My name is %s, my birthday is %s",name,birthday);
}
}


class apples
{
public static void main(String[] args)
{
orange oobj=new orange(2,10,1990);
banana bobj=new banana("harry",oobj);

System.out.print(bobj);
}
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.