Based-class constructor called when creating instances of a derived class

In C# OOP, the keyword base can be used to access members of the base class from within a derived class. Regarding the constructor, the keyword base can specify the base-class constructor called when creating instances of a derived class.


Example

We are making a Chess game and we need to define the chess piece for the players.

public enum Player 
{
    Black,
    White
}

public class ChessPiece //base class
{
    //Properties
    public Player Player { get; set; }
    public char Symbol { get; set; }
    //Constructor
    public ChessPiece(char symbol, Player player)
    {
        Player = player;
        Symbol = symbol;
    }
}

The code above is the base class and the following code is a derived class.

public class King: ChessPiece 
{ 
  public King(Player player) : base('K', player) {}
}

Class King is a derived class from ChessPiece class. We use keyword base to access the constructor in class King.


57 Replies to “Based-class constructor called when creating instances of a derived class”

  1. Hey, I think your blog might be having browser compatibility issues.
    When I look at your blog site in Chrome, it looks fine but when opening in Internet Explorer,
    it has some overlapping. I just wanted to give you a quick heads up!
    Other then that, fantastic blog!

    Check out my blog post: delta 8 thc

  2. Somebody necessarily lend a hand to make seriously articles
    I might state. This is the very first time I frequented your website page and to this point?

    I amazed with the analysis you made to make this actual publish incredible.
    Magnificent process!

    Look into my blog post: buy delta 8 thc online

  3. Please let me know if you’re looking for a article writer for your blog.

    You have some really great articles and I feel I would be
    a good asset. If you ever want to take some of the load off,
    I’d really like to write some material for your blog in exchange for a link back to mine.
    Please send me an e-mail if interested. Kudos!

    Stop by my webpage; delta-8-THC

  4. Actually no matter if someone doesn’t understand after that
    its up to other people that they will assist, so here it takes place.

    Also visit my webpage: buy cbd

  5. Simply want to say your article is as surprising. The clarity in your publish is just nice and i could think you are a professional
    on this subject. Well together with your permission allow me to seize your feed to keep updated with imminent post.
    Thank you 1,000,000 and please carry on the gratifying work.

    my website … cbd for sale

  6. I am not sure where you are getting your information, but good topic.
    I needs to spend some time learning more or understanding more.
    Thanks for excellent info I was looking for
    this info for my mission.

    My webpage … buy cbd

  7. Excellent post. I was checking constantly this blog and I am impressed!
    Extremely useful information specially the last part 🙂 I care for such info much.
    I was seeking this certain information for a very
    long time. Thank you and good luck.

    Also visit my web-site – delta 8 THC area 52

  8. Pretty section of content. I simply stumbled upon your site and in accession capital to
    claim that I get in fact enjoyed account your blog posts.
    Any way I will be subscribing for your feeds and even I success you
    access consistently fast.

    Feel free to visit my web-site: delta 8 thc carts

  9. Hey There. I discovered your weblog the usage of msn. This is an extremely neatly written article.
    I’ll make sure to bookmark it and come back to learn extra of your helpful information. Thank
    you for the post. I will definitely return.

    Here is my website – delta 8 thc

  10. Pretty nice post. I just stumbled upon your blog and wanted to say that
    I have truly enjoyed surfing around your blog posts. After all I will be subscribing to your feed and I hope you write again soon!

    Here is my website best delta 8

  11. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time
    and was hoping maybe you would have some experience with something
    like this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to
    your new updates.

    Visit my web blog :: buy delta 8

  12. Где смотреть Евро-2020? По каким каналам можно посмотреть матчи Евро-2021?
    Полная информация на сайте
    https://cerrajerosrivasvaciamadrid.site/2021/17-smotret-evro-2021-za-1-dollar/?&partner=google&gclid=CjwKCAjwqvyFBhB7EiwAER786ctyeIqW1b5uJtRDpeKA8Cfh9yBcTZuz3NxD4xxEPheId_-sdcVwURoCbwUQAvD_BwE&gclsrc=aw.ds

    Простейшие варианты где можно смотреть Евро-2020 бесплатно или за 1 доллар в месяц в качестве HD.

Leave a Reply

Your email address will not be published. Required fields are marked *