© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
Gyoei

✅ Difficulty understanding Inheritance and where to use Constructor

Hello people. I'm learning OOP and I've come across this problem. I'm creating a Football team creator console app. I have a abstract class called Player which has the base properties. I have four inherited classes (Defender, Midfielder, etc) which all have different skill properties(Passing, Shooting etc).
I have two Questions:
1. Where(in Player or in inherited classes) and how do I put the constructor so it inherits all the properties of Player.
2. I have a DisplayInfo() method in Player Class. I want to use this method in inhertied classes but add additional functionalities to display the skill properties.
Code:
1. Abstract Player Class
 abstract class Player
    {
        //base properties
        internal string Name { get; }
        internal string Position { get; }
        internal string Nationality { get; }

        //physical properties
        //all players are assigned these randomly
        public int Pace { get { return SetPhysicalProperties(60,90); } }
        public int Strength { get { return SetPhysicalProperties(60,90); } }
        
        //Methods
        static int SetPhysicalProperties(int min, int max)
        {
            var rand = new Random();
            return rand.Next(min, max);
        }

        //display Info Method
        public void DisplayInfo()
    {
        var info = new StringBuilder();
        info.AppendLine("-----Personal Details----");
        info.AppendLine($"Name: {this.Name}\tPosition: {this.Position}\t,Nationality:         {this.Nationality}");
        info.AppendLine("----Physical Attributes----");
        info.AppendLine($"Pace: {this.Pace}\tStrength: {this.Strength}\t");
        System.Console.WriteLine(info.ToString());      
 abstract class Player
    {
        //base properties
        internal string Name { get; }
        internal string Position { get; }
        internal string Nationality { get; }

        //physical properties
        //all players are assigned these randomly
        public int Pace { get { return SetPhysicalProperties(60,90); } }
        public int Strength { get { return SetPhysicalProperties(60,90); } }
        
        //Methods
        static int SetPhysicalProperties(int min, int max)
        {
            var rand = new Random();
            return rand.Next(min, max);
        }

        //display Info Method
        public void DisplayInfo()
    {
        var info = new StringBuilder();
        info.AppendLine("-----Personal Details----");
        info.AppendLine($"Name: {this.Name}\tPosition: {this.Position}\t,Nationality:         {this.Nationality}");
        info.AppendLine("----Physical Attributes----");
        info.AppendLine($"Pace: {this.Pace}\tStrength: {this.Strength}\t");
        System.Console.WriteLine(info.ToString());      

2. inherited Defender Class
internal class Defender : Player
    {
        public int Tackling { get; private set; }
        public int SlideTackle { get; private set; }
        public int Header { get; private set; }
    }
internal class Defender : Player
    {
        public int Tackling { get; private set; }
        public int SlideTackle { get; private set; }
        public int Header { get; private set; }
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ Understanding inheritance
C#CC# / help
4y ago
✅ Need help understanding inheritance with constructors
C#CC# / help
3y ago
❔ Abstract forced empty constructor inheritance
C#CC# / help
3y ago
I cant figure out constructor inheritance
C#CC# / help
3y ago