Variables

Nicholas Duchon: Mar 31, 2017

Click here to start

Table of contents

Code:


Code:

public class Z extends X {
  private Y a = new Y(3);

  public Z(int x, int y) {
    super(x);
    a.setValue(y);
  } // end int, int constructor
 
  public String toString () {
    return "From Z: " + a.getValue();
  } // end toString

  public static void main(String[] args) {
    Z myZ = new Z ( 5,  7);
    Z myY = new Z (12, 14);
    System.out.println("value myZ: " + myZ);
    System.out.println("value myY: " + myY.a);
  } // end main

} // end class Z

class Y {
  private int value;

  public Y(int n) {
    value = n;
  } // end int constructor

  public void setValue(int z) {
    value = z;
  } // end method setValue

  public int getValue() {
    return value;
  } // end method getValue

  public String toString () {
    return "From Y: " + value;
  } // end toString
} // end class Y

class X {
  static int count = 0;
  private int data;

  public X(int n) {
    data = n;
  } // end int constructor

  public int getData() {
    return data;
  } // end getData
} // end class X


End.