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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:55:07+00:00 2026-06-03T20:55:07+00:00

I have a little problem in coding in OO way. Here is my code:

  • 0

I have a little problem in coding in OO way.

Here is my code:

 public class BasicEngine
{
    public    string name = null;
    public  string id = null;

    public BasicEngine()
    {
        name = "Name of basic engine type";
        id = "Basic engine id here";
    }

}

public class SuperEngine: BasicEngine  
{
    public  string name = null;
    public  string address = null;

    public SuperEngine()
    {
        name = "Name of super engine here";
        address  = "Super engine  address here";
    }

}

I am making the objects of these classes in the following ways:

       BasicEngine e1 = new BasicEngine();
       MessageBox.Show("e1 type is " + e1.GetType().ToString());

       SuperEngine e2 = new SuperEngine();
       MessageBox.Show("e2 is " + e2.GetType().ToString());

       BasicEngine e3 = new SuperEngine();
       MessageBox.Show("e3 is " + e3.GetType().ToString());

       SuperEngine e4 =BasicEngine(); // error An explicit conversion exist (are you missing cast ?) and if I try to cast it like    SuperEngine e4 =(SuperEngine ) new BasicEngine(); it give run time error.

e1 is BasicEngine as it should be.
e2 is SuperEngine as it should be.

Here are my confusion and questions:

  1. e3 is BasicEngine type and it shows its data, I expect it to be SuperEngine type, why it is ?

  2. e4 give error: error An explicit conversion exist (are you missing cast ?) and if I try to cast it like SuperEngine e4 =(SuperEngine ) new BasicEngine(); it give run time error.

  • 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-03T20:55:08+00:00Added an answer on June 3, 2026 at 8:55 pm

    Q1: This is because e3 is being declared as type BasicEngine. Because SuperEngine inherits from BasicEngine and e3 IS a BasicEngine, it’s going to run the BasicEngine constructor.

    Q2: Your syntax is just wrong. You need to do SuperEngine e4 = new BasicEngine();, but this will still throw an error. This is because the BasicEngine constructor doesn’t know how to create a SuperEngine and therefore won’t. Parent classes are unaware of their derived children, but derived children ARE aware of their parents.

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

Sidebar

Related Questions

I have little problem with a replacement of a little part in an url.
I have little problem in regular expressin creation. Expected input: blahblahblah, blahblahblah, 'blahblahblah', blahblahblah,
I have a little problem with a simple vbScript. The script has to run
I have a little problem with some jquery and http://www.mikage.to/jquery/jquery_history_noc.html The function works great,
I have a little problem where I would like to insert a svn diff
I have this little problem, that I cannot figure out which arguments to pass
I have a little problem with a query. I'm selecting data using the between
I have a little problem about using jQuery (I really do not know jQuery
I have a little problem, I have an array and I want to add
I have a little problem. I had some JComboBox to a JDialog but they

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.