Hi! Well, I could really use some help with explaining this code output.
Here's the code:
class Uppgift2 {
public static void main(String[]args) {
Adda[]alla=new Adda[5];
for (int x=0; x<alla.length; x++)
if (x==1 || x==3)
alla[x]=new Dokee();
else alla[x]=new Bjubb();
for (int x=0; x<alla.length; x++)
alla[x].skriv();
}
}
class Adda {
private String ord="Lire";
private int antal=2;
public Adda(String ord, int antal) {
this.ord=ord;
this.antal=antal;
}
public Adda() {
ord="Pesetas";
}
public void skriv() {
for (int x=0; x<antal; x++)
System.out.print(ord);
System.out.println();
}
}
class Bjubb extends Adda {
private static String[] ord={"Kronor","Dollar","Sedlar","Pengar"};
private static int pos=0;
public Bjubb() {
super(ord[pos++], pos);
}
}
class Dokee extends Adda {
private String sak="Euro";
public void skriv(){
super.skriv();
System.out.println(sak);
}
}
The output is supposed to look like this:
Kronor
PesetasPesetas
Euro
DollarDollar
PesetasPesetas
Euro
SedlarSedlarSedlar
Can anyone explain to me why the output is the way it is? I can figure out some parts, but I'm still a "newbie" when it comes to Java. Thankful for every bit of advice I can get.