Static attributes

Spread the love

package bestpractices;

import java.util.ArrayList;
import java.util.List;
public class StaticUse {

public static void main(String[] args) {
List<Avioneta> listaVehiculos = new ArrayList<>();
for (int i = 0; i < 5; i++) {
Avioneta e = new Avioneta(Math.random()+””);
listaVehiculos.add(e);
System.out.println(e.getCodigoUnico()+”, “+Avioneta.getAerolinea());
}

Avioneta.setAerolinea(“Air buster”);

for (Avioneta av : listaVehiculos) {
System.out.println(av.getCodigoUnico()+”, “+av.getAerolinea());
}
}
}

 

package bestpractices;

public class Avioneta {

private static String aerolinea = “hell”;
private String codigoUnico;

public Avioneta() {

}

Avioneta(String string) {
codigoUnico=string;
}

public String despegar() {
return “nnnniuuum”;
}

public String getCodigoUnico() {
return codigoUnico;
}

public void setCodigoUnico(String codigoUnico) {
this.codigoUnico = codigoUnico;
}

public static String getAerolinea() {
return aerolinea;
}

public static void setAerolinea(String aerolinea) {
Avioneta.aerolinea = aerolinea;
}

}

 

output:

debug:
0.9042191199854238, hell
0.8424079454460117, hell
0.977056225254248, hell
0.7376131612880302, hell
0.6145896966456822, hell
0.9042191199854238, Air buster
0.8424079454460117, Air buster
0.977056225254248, Air buster
0.7376131612880302, Air buster
0.6145896966456822, Air buster
BUILD SUCCESSFUL (total time: 1 second)

 

Comments

comments

Leave a Reply