Will the base class constructor be automatically called?

后端 未结 6 1507
孤街浪徒
孤街浪徒 2020-11-30 20:36
class Person
{
    public int age;
    public Person()
    {
        age = 1;
    }
}

class Customer : Person
{
    public Customer()
    {
        age += 1;
    }
         


        
6条回答
  •  被撕碎了的回忆
    2020-11-30 21:09

    If you did not have a default parameterless constructor then there would be a need to call the one with parameters:

    class Person
    {
        public Person(string random)
        {
    
        }
    }
    
    class Customer : Person
    {
        public Customer(string random) : base (random)
        {
    
        }
    }
    

提交回复
热议问题