Skip to content

Instantly share code, notes, and snippets.

@matthenning
Last active December 14, 2017 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthenning/ca4b2150ecd85ca288638c963f8e72ea to your computer and use it in GitHub Desktop.
Save matthenning/ca4b2150ecd85ca288638c963f8e72ea to your computer and use it in GitHub Desktop.
public class Punkt {
protected int x;
protected int y;
public Punkt(int x, int y) {
this.x = x;
this.y = y;
}
public void addPunkt(Punkt p) {
this.x += p.x;
this.y += p.y;
}
public String toString() {
return "X: " + this.x + ", Y: " + this.y;
}
}
public class PunktZ extends Punkt {
protected int z;
public PunktZ(int x, int y, int z) {
super(x, y);
this.z = z;
}
public void addPunkt(PunktZ p) {
super.addPunkt(p);
this.z += p.z;
}
public String toString() {
return super.toString() + ", Z: " + this.z;
}
}
public class Main {
public static void main(String[] args) {
Punkt p1 = new Punkt(5, 10);
Punkt p2 = new Punkt(3, 8);
p1.addPunkt(p2);
System.out.println(p1.toString());
PunktZ pz1 = new PunktZ(5, 10, 3);
PunktZ pz2 = new PunktZ(3, 8, 1);
pz1.addPunkt(pz2);
System.out.println(pz1.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment