Skip to content

Commit 385f61d

Browse files
authored
Add files via upload
1 parent 67c7173 commit 385f61d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//A java Program to demostrate wrapper class to swap objects of a car
2+
class Box
3+
{
4+
int no;
5+
float length;
6+
float depth;
7+
float width;
8+
Box(int n,float l,float d,float w)
9+
{
10+
no=n;
11+
length=l;
12+
depth=d;
13+
width=w;
14+
}
15+
void characteristics()
16+
{
17+
System.out.println("Box Number:"+no+" Length:"+length+" Depth:"+depth+" Width:"+width);
18+
}
19+
}
20+
21+
//Wrapper class
22+
class BoxWrapper
23+
{
24+
Box myBox;
25+
BoxWrapper(Box obj)
26+
{
27+
myBox=obj;
28+
}
29+
}
30+
31+
/**
32+
* SwapObjects2Solution
33+
*/
34+
public class SwapObjects2Solution {
35+
36+
public static void swap(BoxWrapper mybox1,BoxWrapper mybox2) {
37+
Box temp=mybox1.myBox;
38+
mybox1.myBox=mybox2.myBox;
39+
mybox2.myBox=temp;
40+
}
41+
public static void main(String[] args) {
42+
Box box1=new Box(1,30f,45.5f,67.8f);
43+
Box box2=new Box(2,57f,90f,10f);
44+
BoxWrapper boxw1=new BoxWrapper(box1);
45+
BoxWrapper boxw2=new BoxWrapper(box2);
46+
swap(boxw1,boxw2);
47+
boxw1.myBox.characteristics();
48+
boxw2.myBox.characteristics();
49+
50+
}
51+
}

0 commit comments

Comments
 (0)