-1
I created a class ContaCorrente
as a daughter of a class Conta
.
In class Conta
have a method saca
:
public boolean saca (double valor) {
if (saldo >= valor) {
this.saldo -= valor;
System.out.println("Operação concluída, seu saldo é: "+ saldo);
return true;
} else {
System.out.println("Seu saldo é insuficiente para essa operação");
return false;
}
}
I need to create in the child class a slightly different rule, but reusing this parent class method.
But when I type conta
or saca
and grip Ctrl+space for the Eclipse to suggest Override
method, does not work, does not appear any Override
. What I’m doing wrong?
COMPLETE CLASSES:
class Conta {
private Cliente titular;
private int AG;
private int CC;
private double saldo;
private static int total;
public Conta(int AG, int CC) {
Conta.total ++;
this.AG = AG;
this.CC = CC;
System.out.println("A conta foi criada com sucesso");
System.out.println("Agência: "+ AG);
System.out.println("Conta: " + CC);
}
public void deposita (double valor) {
this.saldo += valor;
}
public boolean saca (double valor) {
if (saldo >= valor) {
this.saldo -= valor;
System.out.println("Operação concluída, seu saldo é: "+ saldo);
return true;
} else {
System.out.println("Seu saldo é insuficiente para essa operação");
return false;
}
}
public boolean transfere (double valor, Conta destino) {
if(this.saldo >= valor) {
this.saldo -= valor;
destino.saldo += valor;
System.out.println("Transação realizada com sucesso, seu novo saldo é: " + this.saldo);
return true;
} else {
System.out.println("Transaão NÃO efetuada, saldo insuficiente!");
return false;
}
}
public double getSaldo() {
return this.saldo;
}
public int getCC() {
return this.CC;
}
public void setCC (int numeroCC) {
CC = numeroCC;
}
public int getAG () {
return this.AG;
}
public void setAG (int numeroAG) {
AG = numeroAG;
}
public Cliente getTitular() {
return titular;
}
public void setTitular(Cliente titular) {
this.titular = titular;
}
public static int getTotal () {
return Conta.total;
}
}
DAUGHTER:
public class ContaCorrente extends Conta {
public ContaCorrente (int AG, int CC) {
super(AG, CC);
}
}
Post your complete classes.
– nullptr
If you type "bag" and Ctrl+space, then it won’t? " account" won’t work because overwrite is in the method, not in the class...
– hkotsubo
even typing bag and Ctrl+space tbm is not going :/
– Jujuba Dev
to be able to override the class needs to be abstract?
– Lucas Miranda
I think not, in exercise classes are with certain definitions
– Jujuba Dev
Create the method in the child class and see if it works. It can be something with auto complete.
– Diego Schmidt
I thank those who tried to help, but I’ll close the question... 3 people already came to edit the question, one editing what the other already edited... apparently people are more worried about appearing than really helping... Thanks to the 3 who tried.
– Jujuba Dev
Diego, I tried to manually create the method in the daughter, but when I put @Overrride, the build error :/
– Jujuba Dev
It doesn’t really need to be Abstract, I tested your classes here the same as it is and it is working yes...
– Lucas Miranda
@Jujubadev Editing the question has nothing to do with "wanting to appear". The site is collaborative and editing is part of the ongoing improvement of the content. Read here and here to learn more
– hkotsubo
Both classes are in the same package?
– Diego Schmidt
They are Diego...
– Jujuba Dev
If it were in another package you would have problem because you did not set the public modifier in the Account class. Try putting the public in the account class anyway.
– Diego Schmidt
Yes I imagined, but I checked now and all the classes are in the same pack
– Jujuba Dev