search
Login

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

0 votes
26 views
asked Sr Member 5k points 7 9 12

1 Answer

0 votes
Add a method to Box,as shown here:

class Box {
  int width;
  int height;
  int depth;
  void calculateVolume() {
    System.out.print("Volume is ");
    System.out.println(width * height * depth);
  }
}

public class Main {

  public static void main(String args[]) {
    Box mybox1 = new Box();
    mybox1.width = 10;
    mybox1.height = 20;
    mybox1.depth = 15;
    mybox1.calculateVolume();
  }
}
answered Guru 24.6k points 29 52 81

Related questions

0 votes
1 answer 104 views
104 views
asked augustaina Sr Member 4.8k points 10 25 31
0 votes
1 answer 46 views
46 views
asked rock Expert 15k points 15 23 30
0 votes
1 answer 58 views
58 views
asked taye Sr Member 5k points 7 9 12
0 votes
1 answer 92 views
92 views
asked augustaina Sr Member 4.8k points 10 25 31
0 votes
1 answer 20 views
20 views
asked augustaina Sr Member 4.8k points 10 25 31
...