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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:20:01+00:00 2026-05-14T21:20:01+00:00

Say I had a class SuperClass and two subclasses SubClassA and SubClassB that inherit

  • 0

Say I had a class SuperClass and two subclasses SubClassA and SubClassB that inherit from SuperClass.

 abstract class SuperClass{
   ...
   List someList;
   ...
 }

 class SubClassA extends SuperClass{
   ...
   List<String> someList;
   ...
 }

 class SubClassB extends SuperClass{
   ...
   List<Integer> someList;
   ...
 }

That way it is convenient because I can get someList.size() in Superclass and have Typesafety in the Subclasses.
The problem is that it does not “feel” right, can you think of potential hazards this apporach has that I am not aware of?

  • 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-14T21:20:02+00:00Added an answer on May 14, 2026 at 9:20 pm

    For one thing, any method of SuperClass sees the superclass list, not that of the subclass. This almost surely leads to subtle bugs. E.g. when you say

    I can get someList.size() in Superclass

    what you actually get is the size of the list in Superclass, not that of the subclass. The superclass list may be empty while the subclass list contains elements (or vice versa).

    The reason behind this is that SubClassA.someList does not in any way replace or override Superclass.someList – it just shadows it, so the subclass methods see SubClassA.someList instead of Superclass.someList. However, this has absolutely no effect in Superclass. Methods can be made virtual (and in Java, they are by default), but data members can’t.

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

Sidebar

Ask A Question

Stats

  • Questions 514k
  • Answers 514k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You are right, there is no difference. Here is a… May 16, 2026 at 6:18 pm
  • Editorial Team
    Editorial Team added an answer Have a look here about what Apple recommends: // Convert… May 16, 2026 at 6:18 pm
  • Editorial Team
    Editorial Team added an answer preload actually takes a value, one of auto, meta or… May 16, 2026 at 6:18 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Assuming that all headers are guarded, let's say you had an abstract data type.
Say I had a library called libfoo which contained a class, a few static
I had a class hierarchy setup like so: public abstract class GameController public abstract
Is it possible for a PHP object instance to destroy/unset itself? Say I had
Say I have a class called PermissionManager which should only exist once for my
Let's say I have a model class called Project, but instead of this: class
With the structure.. abstract class Unit { int Id; } class Measure : Unit
EDIT: I know in this case, if it were an actual class i would
I was compiling a C++ program in Cygwin using g++ and I had a
I saw some code in which the developer defined a class template in 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.