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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:05:05+00:00 2026-05-31T03:05:05+00:00

EDIT: I will leave this here as an example. Read the comments for more

  • 0

EDIT: I will leave this here as an example. Read the comments for more information but generally: DON’T USE THIS DESIGN! It’s BAD!

I searched for an answer for a while now, but couldn’t find anything really specific saying, no you can’t because… or yes you can that’s how you do it..

So the question is, Can I create an abstract method defining Object type parameters and then have something implement it with a concrete Type of parameter like this:

public abstract class ToBeOverriden {
    public Object method1 (Object parameter);
    public String method2 (Object parameter);
    public void method3 (Object parameter);
}

And then override it with this:

public class Implementation {
    @Override
    public DateTime method1 (Person parameter){
        return new DateTime();
    }

    @Override
    public String method2 (MotorCycle parameter){
        return new DateTime();
    }

    @Override
    public void method3 (String parameter){
        return new DateTime();
    }
}

Where Person is an object created by me. Return Type can be whatever. Currently I can’t do this. It doesn’t let me. My guess is that this is because my Class doesn’t extend Object. Although everything extends Object… So…

Or do I need to refresh my Java knowledge? 🙂

EDIT: Added a more complex class structure.

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-31T03:05:06+00:00Added an answer on May 31, 2026 at 3:05 am

    You would need to use Java Generics:

    public abstract class ToBeOverriden<E,V> {
        public E method (V parameter);
    }
    
    public class Implementation extends ToBeOverriden<DateTime,Person> {
        @Override
        public DateTime method (Person parameter){
            return new DateTime();
        }
    }
    

    Added:

    E parameter can be ommited, the code will still compile. However, if different implementations of the ToBeOverriden will use different return types, I think it’s better to retain E. But that’s a matter of personal taste – I don’t like seeing Object anywhere in code.

    Added 2:

    As about your update in the question, you would need to have a separate Generic type for every method. For example:

    public abstract class ToBeOverriden<A,B,C> {
        public Object method1 (A parameter);
        public String method2 (B parameter);
        public void method3 (C parameter);
    }
    

    However, usually, when you need such a horrible structure – then your code is designed the wrong way. In 95% cases 1 generic type parameter is enough. In 4.99% cases 2 generic type parameters are enough.

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

Sidebar

Related Questions

My current solution will suck sometimes EDIT For those who don't understand,see this example:
( Late edit: This question will hopefully be obsolete when Java 7 comes, because
Sorry if this question will sound too chaotic, feel free to edit it. I
EDIT: This question is solved, but I can't accept my own answer just yet.
I need the form that will edit the array of entities and their related
I am trying to implement a control to edit text that will display the
I'm about to start a project that will record and edit audio files, and
I am looking for a tool which will make able to edit parts of
When you go to edit your favorite music or movies on Facebook, you will
I am writing a PHP application that will have the ability to edit settings

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.