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

  • Home
  • SEARCH
  • 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 563035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:37:02+00:00 2026-05-13T12:37:02+00:00

I was explaining OOP to my friend. I was unable to answer this question.

  • 0

I was explaining OOP to my friend. I was unable to answer this question.

I just escaped by saying, since OOP depicts the real world. In real world, parents can accommodate children but children cannot accommodate parents. same is the case in OOP.

class Parent
{
  int prop1;
  int prop2;
}

class Child : Parent // class Child extends Parent  (in case of Java Lang.)
{
  int prop3;
  int prop4;
  
  public static void Main()
  {
     Child aChild = new Child();
     Parent aParent = new Parent();
     aParent = aChild;// is perfectly valid.
     aChild = aParent;// is not valid. Why??
 
  }
}

Why isn’t this statement valid?

 aChild = aParent;// is not valid. Why??

since aChild‘s members are superset of aParent‘s members. Then why can’t aChild accommodate a parent.

  • 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-13T12:37:03+00:00Added an answer on May 13, 2026 at 12:37 pm

    Exactly because aChild is a superset of aParent’s abilities. You can write:

    class Fox : Animal
    

    Because each Fox is an Animal. But the other way is not always true (not every Animal is a Fox).

    Also it seems that you have your OOP mixed up. This is not a Parent-Child relationship, because there’s no composition/trees involved. This is a Ancestor/Descendant inheritance relation.

    Inheritance is “type of” not “contains”. Hence it’s Fox is a type of Animal, in your case it doesn’t sound right — “Child is a type of Parent” ? The naming of classes was the source of confusion ;).

    class Animal {}
    class Fox : Animal {}
    class Fish : Animal {}
    
    Animal a = new Fox(); // ok!
    Animal b = new Fish(); // ok!
    Fox f = b; // obviously no!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one will take some explaining. What I've done is create a specific custom
A friend of mine was explaining how they do ping-pong pairing with TDD at
Ugh ok I'm terrible at explaining things, so I'll just give you the quotes
This one is a bit tedious in as far as explaining, so here goes.
This post reference to the One Definition Rule. Wikipedia is pretty bad on explaining
What is the DIRECTORY_SEPARATOR constant contain? I can't find anything on google explaining this
This link is explaining how to do it in an edge transport environment, indicating
I am having trouble explaining this to myself but here is my best attempt.
I did a poor job of explaining my original question, so here's a second
I don't know if I am explaining this correctly, or if the solution is

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.