title: Printing a method from the main method
body: <p>I'm fairly new to <code>java</code> and I am wondering how I can print the <code>Boxvolume</code> variable from my <code>volume</code> method.</p>
  
  <p>I do understand that I need to make <code>Boxvolume</code> a global variable. So if anyone can help me with that it would be very much appreciated.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public static void main(String[] args) {
      Box a = new Box(20, 30, 40);
  
      ArrayList&lt;Box&gt; boxes = new ArrayList&lt;&gt;();
      boxes.add(a);
  
      for (Box bx : boxes) {
          bx.print();
      }
  
      double V = volume(Boxvolume);
      System.out.println(V);
  }
  
  class Box {
      int width;
      int height;
      int depth;
  
      public Box(int w, int h, int d) {
          this.width = w;
          this.height = h;
          this.depth = d;
      }
  
      public double volume(double BoxV) {
          int Boxvolume = width * height * depth;
          return Boxvolume;
      }
  
      public double price(double BV) {
          double Boxprice = volume(BV) * 5;
          return Boxprice;
      }
  
      public void print() {
          System.out.println(this.width);
          System.out.println(this.height);
          System.out.println(this.depth);
          System.out.println();
      }
  }
  </code></pre>