fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Rectangle r1 = new Rectangle(2);
  13. Cube c = new Cube(r1);
  14. Rectangle r = c.getFace();
  15. System.out.println(c.volume()+"\n");
  16. r.a = 3;
  17. System.out.println(c.volume());
  18. }
  19. }
  20.  
  21. class Rectangle {
  22. int a = 0;
  23. public Rectangle(int r) {
  24. a = r;
  25. }
  26. public int getLength() {
  27. return this.a;
  28. }
  29. }
  30.  
  31. class Cube {
  32. private Rectangle mFace;
  33.  
  34. public Cube(Rectangle rectangle) {
  35. mFace = rectangle;
  36. }
  37.  
  38. public Rectangle getFace() {
  39. return mFace;
  40. }
  41.  
  42. public int volume() {
  43. int length = this.mFace.getLength();
  44. return length * length * length;
  45. }
  46. }
Success #stdin #stdout 0.08s 33940KB
stdin
Standard input is empty
stdout
8

27