Okay, so what I need help with is the relations between the classes and the methods. I've heard about association and aggregation, but I don't know how to use them, or even if they fit in this code.
Also, I would like to know what super()
does and what does p3=p3In
in class Pgm2
.
public class Pgm1 {
public Pgm1() {
System.out.println("Konstruktor Pgm1");
}
public void skriv() {
System.out.println("Skriv i Pgm1");
}
public static void main(String[] args) {
Pgm3 p3=new Pgm3();
p3.skriv();
Pgm4 p4=new Pgm4(p3);
p4.skriv();
Pgm2 p2=new Pgm2();
p2.skriv();
}
}
public class Pgm2 {
private Pgm1 p1;
public Pgm2() {
p1=new Pgm1();
System.out.println("Konstruktor Pgm2");
}
public void skriv() {
System.out.println("Skriv i Pgm2");
}
}
public class Pgm3 {
public Pgm3() {
System.out.println("Konstruktor Pgm3");
}
public void skriv() {
System.out.println("Skriv i Pgm3");
}
}
public class Pgm4 extends Pgm2 {
private Pgm3 p3;
public Pgm4(Pgm3 p3In) {
super();
p3=p3In;
System.out.println("Konstruktor Pgm4");
}
public void skriv() {
System.out.println("Skriv i Pgm4");
}
}