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 6083417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:24:04+00:00 2026-05-23T11:24:04+00:00

Alright, so here’s the exercise: You must define three classes. One class named MyNum

  • 0

Alright, so here’s the exercise:
You must define three classes. One class named MyNum that contains a variable of type int. Second class called MyString, will be derived from MyNum and contains string. Third-class call MyType and returns a variable of type MyNum. Each class will be set to a constructor function and virtual function called Show. The constructor function of MyType receive a MyNum variable, whereas the function Show of MyType will run the Show function of MyNum.
Now, you need set two objects of type MyType and initialize them. Once an object type MyNum and once an object of type MyString.

Here’s the code:

class MyNum
{
    protected int num;
    public MyNum(int num)
    {
        this.num = num;
    }
    public virtual void Show()
    {
        Console.WriteLine("The number is : " + num);
    }
}
class MyString : MyNum
{
    string str;
    public MyString(string str)
    {
        this.str= str;
    }
}
class MyType : MyNum
{
    MyNum num2;
    public MyType(MyNum num)
    {
        this.num2 = num;
    }
    public override void Show()
    {
        base.Show();
    }
}
class Program
{
    static void Main(string[] args)
    {

    }
}

I’m having the following error:

Error 1 ‘ConsoleApplication1.MyNum’ does not contain a constructor that takes ‘0’ arguments C:\Users\x\AppData\Local\Temporary Projects\ConsoleApplication1\Program.cs 23 16 ConsoleApplication1

Anyone knows why am I having this error? Thanks.

  • 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-05-23T11:24:05+00:00Added an answer on May 23, 2026 at 11:24 am

    Since your class subclasses MyNum, it needs to be able to construct it. You don’t have a default constructor, so you have to explicitly call it with a value.

    For example:

                 // Since this is here, you're saying "MyType is a MyNum"
    class MyType : MyNum
    {
        MyNum num2;
        public MyType(MyNum num) // You need to call the base class constructor 
                                 // here to construct that portion of yourself
           : base(42) // Call this with an int...
        {
            this.num2 = num;
        }
    

    The class MyString will need similar treatment. It will have to have a constructor that calls the base class constructor, too.

    Note that, if the MyNum class had a default constructor (which could be protected), this wouldn’t matter. Instead of calling these constructors, the other alternative is to do something like:

    class MyNum
    {
        public MyNum(int num)
        {
            this.num = num;
        }
    
        // Add a default constructor that gets used by the subclasses:
        protected MyNum()
            : this(42)
        {
        }
    

    Edit in response to comments:

    If you want to override the base class constructor, try:

    class MyType : MyNum
    {
        public MyType(int num)
           : base(num)
        {
        }
    
        public override void Show()
        {
              Console.WriteLine("The number [MyType] is : " + this.num);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I have a strange one here. We currently have a tools application that
Alright so here is my issue. I'm working a game engine that will eventually
Alright so here is the deal. I am trying to make a application that's
Alright, I'm having some issues and I believe it's a CSS one. Here is
Alright, here's my dillema. I am making a simple application with Qt Creator that
Alright, so here's my problem. I'm trying to write a script in PHP that
Alright. So I asked a question here but I feared that I anwsered it
Alright here's the situation, I have an application written in the Zend_Framework, that is
Alright, here's an odd one from an MS Access database I'm running. I have
Alright, here we go. I have a cocos2d app, and there are targets that

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.