Using child class attributes

Asked

Viewed 17 times

0

I have an object from the Account class "Account Lectured" however, using polymorphism daughter classes are assigned to Lectured.

public AlterarLimites(Conta conta) {
    contaSelecionada = conta;
    type = 1;
    initComponents();
}

public AlterarLimites(Poupanca conta) {
    contaSelecionada = conta;
    type = 2;
    initComponents();
}

public AlterarLimites(Salario conta) {
    contaSelecionada = conta;
    type = 3;
    initComponents();
}

however I cannot access exclusive methods of the child classes of Account in this way. what could I do to access them?

  • is missing code and an object declared as Conta you want to access something exclusive of ContaSelecionada, that’s it ?

  • Basically that’s what’s explained in the duplicate, it’s a covariance problem, which means you can’t treat a supertype with a subtype.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.