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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:19:25+00:00 2026-05-30T22:19:25+00:00

Well, since I’m typing this from mobile I can’t type or copy paste the

  • 0

Well, since I’m typing this from mobile I can’t type or copy paste the whole code hence I’m linking to the SO post –> What is the error in this code? Interview

If you do
X a = new Y();
it compiles. An interviewer asked how is this possible? I know this will be possible if X was defined as abstract class, but that isn’t the case either.

  • 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-30T22:19:26+00:00Added an answer on May 30, 2026 at 10:19 pm

    To expand on Branko Dimitrijević’s answer, this is possible because of the Liskov substitution principle.

    In your comment, you said

    the base class and derived class can have their own distinct and different method/property/field definitions. So logically that statement shouldn’t compile…but it does…i don’t know the rationale behind it

    It’s true that the base class and the derived class have their own member definitions, but they are not entirely distinct and different. Specifically, every member of the base class is also a member of the derived class. For example, you can always say

    object o = anything;
    Console.WriteLine(o.ToString());
    Console.WriteLine(o.GetHashCode());
    Console.WriteLine(o.GetType().Name);
    

    You can do that because every object has ToString, GetHashCode, and GetType methods, because every object’s runtime type inherits either directly or indirectly from object.

    You can do the same with a base class other than object:

    class X
    {
        public string Exclamation { get { return "Inherit this!"; } }
    }
    class Y : X
    {
        public string Question { get { return "What's up with that?"; } }
    }
    

    Then it’s perfectly legal to say

    X x = new Y();
    Console.WriteLine(x.Exclamation);
    

    But of course, you can’t say

    X x = new Y();
    Console.WriteLine(x.Question);  //does not compile!
    

    In order to use the Question property, you need to have a reference of type Y.

    To recap: because every member of the base class is also a member of the derived class, you can use an instance of the derived class as if it were an instance of the base class. The derived class instance has all of the members of the base class.

    You raised the subject of abstract classes. An abstract class cannot be instantiated, of course; you can only instantiate a class derived from the abstract class. That doesn’t affect the substitution principle, however, except to imply that a variable whose type is an abstract class must refer to an instance of a derived type, while a variable whose type is a non-abstract (unsealed) class may refer to an instance of a derived type.

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

Sidebar

Related Questions

(I have tagged this question as Python as well since I understand Python code
Well since i installed IE 8 i get this error so i cant debug
Well, since I am facing some issues with OAuth implementation, I decided to go
Since the GOF book was put together well before .Net came into being, are
I represent dates using seconds (and microseconds) since 1970 as well as a time
Well, this is my first post here and really enjoying the site. I have
I've used it once, not very well since I found hard to get by
I have this anchor locating regex working pretty well: $p = '%<a.*\s+name=(.*)\s*>(?:.*)</a>%im'; It matches
Well, I've been trying to change the default theme of spree by following this
Well since it seems relatively difficult to send the object of a WebControl over

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.