Guest User

testjava

a guest
Feb 2nd, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. class Box{
  2.  
  3.  
  4. private int w;
  5. private int h;
  6. private int d;
  7.  
  8. /*public int getW(){
  9. return w;
  10. }
  11. public void setW(int w){
  12. this.w=w;
  13. }
  14. public void setH(int h){
  15. this.h=h;
  16. }
  17. public int getH(){
  18. return h;
  19. }
  20. public void setD(int d){
  21. this.d=d;
  22. }
  23. public int getD(){
  24. return d;
  25. }
  26. */
  27.  
  28. Box(){}
  29.  
  30. Box(int w,int h,int d){
  31. this.w=w;
  32. this.h=h;
  33. this.d=d;
  34. }
  35.  
  36. Box(Box box){
  37. w=box.w;
  38. h=box.h;
  39. d=box.d;
  40. }
  41. double vol(){
  42. return w*h*d;
  43. }
  44. }
  45. class Weight extends Box{
  46. int weight;
  47. double vol;
  48. Weight(int w,int h,int d, int wt){
  49. super(w,h,d);
  50.  
  51. /*Box b3=new Box();
  52. b3.setD(d);
  53. b3.setH(h);
  54. b3.setW(w);
  55. Box b4=new Box(b3);
  56. */
  57. weight=wt;
  58. }
  59. }
  60. public class Examle6 {
  61.  
  62. public Examle6() {
  63. }
  64.  
  65. public static void main(String[] args) {
  66. // Box b=new Box(10,20,30);
  67. /* Box b=new Box();
  68. b.w=10;
  69. b.h=20;
  70. b.d=30;
  71. b.setD(30);
  72. b.setH(20);
  73. b.setW(10);
  74. Box b1=new Box(b);
  75. System.out.println("Width: "+b.getW());
  76. System.out.println("Height: "+b.getH());
  77. System.out.println("Depth: "+b.getD());*/
  78. // System.out.println("Volume: "+b.vol());
  79. Weight ww=new Weight(4,5,6,7);
  80. System.out.println("New Volume: "+ww.vol());
  81. System.out.println("Weight: "+ww.weight);
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment