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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:24:39+00:00 2026-05-26T21:24:39+00:00

I was explaining to a friend a few days ago the concept or inheritance

  • 0

I was explaining to a friend a few days ago the concept or inheritance and containers.

He has very little programming knowledge so it was really just a friendly chat.
During the conversation he came to me with a question that i just couldn’t answer.

“Why cant you just have an array of the top level class, and add anything to it”

I know this is a bad idea having being told so before by someone far smarter but for the life of me i couldn’t remember why.

I mean we do it all the time with inheritance.

Say we have class animal which is parent of cat and dog. If we need a container of both of these we make the array of type animal.

So lets say we didn’t have that inheritance link, couldn’t we just use the base object class and have everything in the one container.


No specific programming language.

  • 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-26T21:24:40+00:00Added an answer on May 26, 2026 at 9:24 pm

    Syntactically, there is no problem with this. By declaring an array of a specific type, you are giving implicit information about the contents of that array. You could well declare a contain of Object instances, but it means you lose all the type information of the original class at compile-time.

    It also means that each time you get an object out of the array at runtime, the only field instances and methods you know exist are the fields/methods of Object (which arguably is a compile time problem). To use any of the fields and methods of more specific subclasses of the object, you’d have to cast.

    Alternatively, to find out the specific class at runtime you’d have to use features like reflection which are overkill for the majority of cases.

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

Sidebar

Related Questions

A friend of mine was explaining how they do ping-pong pairing with TDD at
Here I am explaining the scenario - The user, after providing a service has
Ugh ok I'm terrible at explaining things, so I'll just give you the quotes
While explaining when private inheritance must be used, instead of containment, the author of
I was explaining OOP to my friend. I was unable to answer this question.
For pupose of explaining let's say that I have a Company object which has
Let me start by explaining. I have a few global database connections and have
Thanks for help with explaining to me about IList and IEnumerable. I have marked
The question is self-explaining, how to create a tearoff menu using GTKAda? I can't
I need help explaining to my boss why her design is poor on a

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.