here is my code. I want to increase speed value with a.Quest()
method. This method is in the first class. And the second class inherits from first class.
Increasing method is in second class but I use it in first class. That's what I'm trying to do. I don't want to write so much code in main.
However when I run the program, both a.Speed
and b.Speed
is equal to zero. I expect one of them to be 10. How can I fix that?
interface IElektroBeyin
{
int Speed{ get; set; } // Hız kontrolü
}
class AA : IElektroBeyin
{
public int Speed { get; set; }
public virtual void GetFaster() { }
public virtual void GetSlower() { }
public void Quest()
{
int x;
Console.WriteLine("Want to get faster ? 1- Yes");
x = Console.Read();
if (x == 1)
{
GetFaster();
}
}
}
class BB : AA
{
public override void GetFaster()
{
Speed += 10;
}
public override void GetSlower()
{
Speed -= 10;
}
}
static void Main(string[] args)
{
BB b = new BB();
AA a = new AA();
a.Quest();
Console.WriteLine(b.Speed);
Console.WriteLine(a.Speed);
Console.ReadLine();
}
}
}