locked
Explain the usage? RRS feed

  • Question

  • User1002530435 posted

    What is the real use of base keyword.I know that its using to access the base class variables from any other class.But i would like know the insight about it.Please help

    In the below code :base(symbol,price) is just to access the base class parameters.

    Generally to access base class we just want to create a object instance in derived clas to access it.But then whats is the use of base keyword

     class IBM : Stock
            {
                // Constructor
                public IBM(string symbol, double price)
                    : base(symbol, price)
                {
                }
            }

    Wednesday, January 14, 2015 3:03 AM

Answers

  • User-1618234021 posted

    In this specific example, you are calling a specific constructor from the base class. By default when you create an object of IBM class, it will call default (parameter-less) constructor from the Stock class. BUT you are specifying here using the base keyword that call the parameterized constructor from the Stock class that takes 2 parameters, string symbol and double price.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 14, 2015 3:13 AM

All replies