This is the code where I defined a class Animal
and a creator method that asks the species of the animal and defines its state as alive:
public class Animal
{
public bool estaVivo, usaDrogas = false;
string Especie;
public Animal()
{
bool estaVivo = true;
Console.WriteLine("Qual a espécie desse animal?");
Especie = Console.ReadLine();
Console.WriteLine(estaVivo);//debug
}
Next, I have the home class, which inherits from Animal
public class Domestic : Animal
{
public Domestico()
{
Console.WriteLine("Qual o nome do seu bicho de estimação?");
Nome = Console.ReadLine();
Console.WriteLine("Qual a idade do seu bicho de estimação? (NUMERIC)");
Idade = Convert.ToInt32(Console.ReadLine());
}
}
Finally the main method where you instantiate the object:
static void Main(string[] args)
{
Domestico bicho = new Domestico();
Console.WriteLine(bicho.estaVivo);//debug
Console.ReadKey();
}
The question is, why when the constructor method of the Animal
class is called the value of this alive is True
, as intended, however when instantiating the derived class Domestico
the value becomes False
also I can not change its value).