Java Tutorial 2:Passing of Object



class box{
 double vol;
 double wt;
 double ht;
 double bt;
 box (box ob)
 {
 wt=ob.wt;
 ht=ob.ht;
 bt=ob.bt;
 }
 box(double w,double h,double b)
 {
 wt=w;ht=h;bt=b;
 }
 box()
 {
 wt=ht=bt=-1;
 }
 box(double h)
 {
 wt=ht=1;
 bt=h;
 }
 void area()
 {
 vol= wt*ht*bt;
 }
 void show()
 {    if (vol==-1)
 System.out .println("plz give input");
 else
 System.out.println("volume of" +wt+ " " +ht+" "+bt+" is "+vol);
 }
 }

public class volume {

public static void main(String argv[])
 {

box mybox1=new box();
 box mybox2=new box(2,2,2);
 box mybox3=new box(3);
 mybox1.area();
 mybox2.area();
 mybox3.area();
 System.out.println("\nbox1");
 mybox1.show();
 System.out.println("\nbox2");
 mybox2.show();
 System.out.println("\nbox3");
 mybox3.show();
 }
 }

Advertisements

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s