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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:42:35+00:00 2026-05-14T07:42:35+00:00

I have an abstract class Airplane, and two classes PassengerAirplane and CargoAirplane, which extend

  • 0

I have an abstract class Airplane, and two classes PassengerAirplane and CargoAirplane, which extend class Airplane.
I also have an interface Measurable, and two classes that implement it – People and Containers.
So, Airplane can do many things on its own, and there is a method which allows measurable things to be added to the airplane (called addAMeasurableThing). The only difference between PassengerAirplane/CargoAirplane and just an Airplane is that addAMeasurableThing should only accept People / Containers, and not any kind Measurable things. How do I implement this?

I tried doing:
Airplane class:

public abstract Airplane
addAMeasurableThing (Measurable m, int
position);

PassengerAirplane class:

public Airplane addAMeasurableThing
(Measurable m, int position) { if (m
instanceof People)…

CargoAirplane class:

public Airplane addAMeasurableThing
(Measurable m, int position) { if (m
instanceof Containers)…

But when I was debugging it, I’ve noticed that addAMeasurableThing in the CargoAirplane class never gets called, because both methods have the same signature. So how can the appropriate PassengerAirplane/CargoAirplane’s addAMeasurableThing be called, depending on the type of Measurable thing that is being passed on?

Thanks!

  • 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-14T07:42:35+00:00Added an answer on May 14, 2026 at 7:42 am

    Use generics:

    abstract class Airplane<M extends Measurable>{
        public abstract Airplane addAMeasurableThing(M m, int position);
    }
    
    class PassengerAirplane extends Airplane<People>{
        @Override
        public Airplane addAMeasurableThing(People p, int position{ ... }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an abstract class and two sub classes that extend it. I have
I have an abstract class MotherClass and two abstract classes ChildClass1 and ChildClass2 that
I have an abstract base class which acts as an interface. I have two
I have an Abstract class called Function which has 2 inheriting classes (actually 6,
I have an abstract class that is inherited by a number of other classes.
I have an abstract class, AbsClass that implements an interface, IClass . IClass has
I have an abstract class Step, and many descendant Step classes that I would
I have one main interface and an abstract class implementing all derivable methods (that
I have an abstract class that other classes are inheriting this. public abstract class
I have an abstract class that has a shared method which creates a new

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.