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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:57:54+00:00 2026-06-01T08:57:54+00:00

I have an interface (called Subject ) that has the following method: public void

  • 0

I have an interface (called Subject) that has the following method:

public void addObserver(Observer o);

I then have another interface that extends Subject called TimerSubject. This interface is a more specific version of Subject, used for timing. It has a few other miscellaneous methods.

There are also the two corresponding interfaces, Observer, and TimerObserver. TimerObserver extends Observer.

When a class implements TimerSubject, it has to override the addObserver() method from the Subject interface. That looks like this:

@Override
public void addObserver(**Observer e**) {
    observers.add(e);
}

The problem is, I need the method to accept a TimerObserver instead of Observer, whitch would look like this:

@Override
public void addObserver(**TimerObserver e**) {
    observers.add(e);
}

This does not work, since the arguments are not the same as the arguments from the method being overridden.

So is there a way to override a method with arguments that are polymorphic?

  • 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-06-01T08:57:55+00:00Added an answer on June 1, 2026 at 8:57 am

    A few solutions come to mind:

    Your TimerSubject implementation could implement public void addObserver (Observer) by throwing a RuntimeException if it receives an argument that is not a TimerObserver. You lose the protection of the compiler forcing types on you, but late binding is fairly typical to “true” polymorphism.

    Alternatively, your TimerSubject interface could simply specify a new method, addTimerObserver, for the new behavior. Presumably your TimerSubject extends a Subject which already has an implementation of addObserver(Observer); if that implementation would be entirely defunct, you can override and throw an error. But if TimerSubject really has no use for an addObserver(Observer) method and that method is entirely defunct, then perhaps these two objects are not as polymorphic as you’d like. 🙂

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

Sidebar

Related Questions

I have an interface that contains a single method called ListAll() using System.Collections.Generic; namespace
I have a basic core interface called IComponent. public interface IComponent { void Initialize();
I have an interface called Dictionary which has a method insert() . This interface
I have a class Interface, that has pure virtual methods. In another class I
I have interface Foo public interface Foo { public void test(); } Class FooChild
I have an interface that has large numbers of controls, see image below. Interface
I have an interface called ICatalog as shown below where each ICatalog has a
I have an Interface called IStep that can do some computation (See Execution in
I have an interface called IAddress, and a class called Address that handles street,
I have an interface called IEditor public interface IEditor<T> where T: SpecialObject SpecialObject 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.