Good evening, I was commissioned to carry out a simple program in the POO class in which it consists of doing a simple program in which it consists of a Bank where you can enter or withdraw money. I did it in 2 classes, but in the second class it does not let me declare private objects, it only helps me if I create the objects within the main method and without the private.
Class 1:
public class Cuenta{
private String titular;
private double saldo;
public Cuenta(String nombre, double dinero){
titular = nombre;
saldo = dinero;
}
public void ingresar(double dinero){
saldo = saldo + dinero;
}
public void retirar(double dinero){
if(dinero<=saldo)
saldo = saldo-dinero;
}
public double checar(double dinero){
return saldo;
}
}
Class 2:
public class Banco{
private Cuenta cuenta1 = new Cuenta("Carlos Carrete", 2500);
private Cuenta cuenta2 = new Cuenta("Daniela Pabon", 200);
public static void main (String [] args){
cuenta1.ingresar(200);
cuenta2.ingresar(100);
cuenta1.retirar(100);
}
}
Class 2 shows "non static variable can not be referend from static context"