There is the conceptual error, or the question does not make sense. It has another class, but has no other object. It would be good to read What is the difference between a class and an object? to better understand.
Inheritance is a way of creating a new class, that is, a model, without having to specify everything that already exists in the mother class and serves well for the daughter class. It has nothing to do with harnessing data in the object, and in fact it doesn’t even make much sense. Maybe I didn’t quite understand how inheritance works, because I would use it, even if it hardly makes sense of truth, I’ll consider it just to test the mechanism.
When you are creating an object and storing in exemplo
is only dealing with the daughter class. further, there is no variable passing anywhere.
Strictly should not only pass the agency. In fact a coreto code should test this and not accept if the other data is missing.
There seem to be other conceptual errors but I won’t talk because I have no more information.
The most organized code (pay attention to the details)):
class Banco {
constructor(agencia, conta, saldo) {
this.agencia = agencia;
this.conta = conta;
this.saldo = saldo;
}
exibir() {
console.log(this.saldo);
}
}
class NovoBanco extends Banco {
exibirAgencia() {
console.log(this.agencia);
}
}
var exemplo = new NovoBanco('1111-1');
exemplo.exibirAgencia();
I put in the Github for future reference.
Making the correction in
"...Digamos que eu queira utilizar a variável agencia em outra classe..."
and"...Existe alguma forma de utilizar essa variável em outra classe..."
the appropriate name for that structure intended to access a data hosted in a class or object whose membership is called Estate.– Augusto Vasques