Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:07:40+00:00 2026-06-10T09:07:40+00:00

Pass a derived class reference to a base class reference does this means that

  • 0

Pass a derived class reference to a base class reference

does this means that call a base class from the derived class, like the constructor triangle will call the base class?

class Shape {
public int width, height;
 public Shape(int x) { 
    width = height = x; 
    } 
}

class Triangle : Shape { 
 public string style;
  public Triangle(int x) : base(x) { 
    style = "isosceles";  
  } 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:07:42+00:00Added an answer on June 10, 2026 at 9:07 am

    Yes, it will instruct the runtime to invoke that base Shape constructor before Triangle’s.

    The logic executes in this order:

    1. Execute Shape(int x)
    2. Execute Triangle(int x)

    You can therefore direct calls to different constructor overloads if you have them. Also note that if your base class has a parameterless constructor, there’s essentially an implicit base() added if you do not specify one. That means if your base class does not have a parameterless constructor, all subclasses must make a valid base(...parameters...) in their constructor.

    Also, you can use this() instead of base to target a constructor on the current subclass class.

    public class MyBaseClass
    {
        public MyBaseClass()
        {
            Console.WriteLine("MyBaseClass Parameterless");
        }
    
        public MyBaseClass(string message)
        {
            Console.WriteLine("MyBaseClass Message: " + message);
        }
    }
    
    public class MySubClass
    {
        public MySubClass()
        {
            Console.WriteLine("MySubClass Parameterless");
        }
    
        public MySubClass(string message)
            : base(message)
        {
            Console.WriteLine("MySubClass Message: " + message);
        }
    
        public MySubClass(bool someUselessFlag)
            : this()
        {
            Console.WriteLine("MySubClass bool someUselessFlag constructor");
        }
    }
    

    The outputs would be:

    var a = new MySubClass();
    //outputs:
    //MyBaseClass Parameterless
    //MySubClass Parameterless
    
    var b = new MySubClass("Hello World!");
    //outputs:
    //MyBaseClass Message: Hello World!
    //MySubClass Message: Hello World!
    
    var c = new MySubClass(true);
    //outputs:
    //MyBaseClass Parameterless
    //MySubClass Parameterless
    //MySubClass bool someUselessFlag constructor
    

    Constructors chain on themselves until they eventually call the Object() base constructor. That’s why var c = new MySubClass(true) calls more than two constructors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class( Base ) whose constructor takes a reference as argument.
Can I pass arguments to Scala class constructor that are not stored into class
I'm trying to make a base class that defines the interfaces for all derived
Regarding when call copy constructor of base class, we have the form: DerivedClass (
Consider the following example: class Base(models.Model): myfield = models.CharField() class Derived(Base): pass Now, the
If I pass the derived class testA a PlaceHolder that contains a Hyperlink ,
I'd like to define an abstract base class and then pass an array of
I have a Base class, that is considered read-only, and in it's virtual desructor
You have a class, that perfectly fits to be an abstract, but this class
Suppose I have class Base and Derived : public Base . I have constructed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.