PruebaStatic.java 747 Bytes
Newer Older
Joel Florentin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
public class PruebaStatic {
    public static void main(String[] args) {
        Factura f = new Factura();
        f.preciosProductos = new int[]{100,50,120};
        Factura.setIva1(10.f);
        Factura.setIva2(5.f);
    }
}

class Factura{
    private static float iva1;
    private static float iva2;
    int [] preciosProductos;

    public static float getIva1() {
        //preciosProductos[2]=3;error: non-static variable preciosProductos cannot be referenced from a static context
        return iva1;
    }

    public static float getIva2() {
        return iva2;
    }

    public static void setIva1(float iva1) {
        Factura.iva1 = iva1;
    }

    public static void setIva2(float iva2) {
        Factura.iva2 = iva2;
    }

}