How do I call a function in a class

Ok I have a base class and a derived class as you will see in my code. I want to call the function public override void input() from Warrior class.

Here is my code:


public class Character
    {
        private string name;
        private int life;
        private string choice;
        private string answer;
        private bool mHeal = false;
        private Random randomMoney = new Random();
 
        public int RandomMoney
        {
            get
            {
                return randomMoney.Next(100);
            }
        }
        public bool Heal
        {
            get
            {
                return mHeal;
            }
            set
            {
                mHeal = value;
            }
        }
        public string Name
        {
            get
            {
                return (this.name);
            }
            set
            {
                this.name = value;
            }
        }
        public int Life
        {
            get
            {
                return (this.life);
            }
            set
            {
                this.life = value;
            }
        }
        public virtual int calcPoints()
        {
            return Life;
        }
        public virtual void input()
        {
            Console.Write("Character's Name: ");
            this.Name = Console.ReadLine();
 
            Console.Write("Amount of life points: ");
            this.Life = int.Parse(Console.ReadLine());
 
            Console.Write("Will you be a healer?(true or false): ");
            answer = Console.ReadLine();
            if (answer.ToUpper() == "TRUE")
            {
                this.Heal = true;
            }
            else
                this.Heal = false;
 
            Console.Write("Pick a character class W - Warrior, M - Mage, S - Stalker: ");
            choice = Console.ReadLine();
            if (choice.ToUpper() == "W")
            {
                Console.Write("Warrior");
            }
            if (choice.ToUpper() == "M")
            {
                Console.Write("Mage");
            }
            if (choice.ToUpper() == "S")
            {
                Console.Write("Stalker");
            }
 
        }
        public class Warrior : Character
        {
            public int strength;
 
            public int Strength
            {
                get
                {
                    return (this.strength);
                }
                set
                {
                    this.strength = value;
                }
            }
            public override void input()
            {
                Console.Write("Warrior");
            }
        }
    }
    public class Program
    {
        static void Main(string[] args)
        {
            Character character = new Character();
 
            character.input();
 
            MessageBox.Show(string.Format("Character Name: {0}\nLifepoints: {1}\nHealer Class: {2}\nStarting Gold: {3}", character.Name, character.calcPoints(), character.Heal, character.RandomMoney));
 
        }
    }

Open in new window

jschmuffAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JimBrandleyCommented:
Just invoke:
base.Input();

Jim
0
JimBrandleyCommented:
Now, I'm confused about which you wanted. To invoke Input in the Warior class from the Warior class,
this.Input();
or just
Input();

To invoke the one from the base class in the Warior class,
base.Input();

Jim
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jschmuffAuthor Commented:
I want to call in the base class for warrior.input()
0
jschmuffAuthor Commented:
I figured it out thanks the code I posted was incorrect since I didnt notice that the sub class was created within the base class so it wasnt taking on the roll of a derived class.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.