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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:59:18+00:00 2026-06-18T07:59:18+00:00

Can overridden methods have different return types ?

  • 0

Can overridden methods have different return types?

  • 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-18T07:59:19+00:00Added an answer on June 18, 2026 at 7:59 am

    Java supports* covariant return types when overriding methods. An overriding method may have a more specific return type than the method being overridden. That is, as long as the new method’s return type is assignable to the return type of the method it overrides, it’s allowed.

    For example:

    class ShapeBuilder {
        ...
        public Shape build() {
        ....
    }
    
    class CircleBuilder extends ShapeBuilder{
        ...
        @Override
        public Circle build() {
        ....
    }
    

    This is specified in section 8.4.5 of the Java Language Specification:

    Return types may vary among methods that override each other if the return types are reference types. The notion of return-type-substitutability supports covariant returns, that is, the specialization of the return type to a subtype.

    A method declaration d1 with return type R1 is return-type-substitutable for another method d2 with return type R2, if and only if the following conditions hold:

    • If R1 is void then R2 is void.

    • If R1 is a primitive type, then R2 is identical to R1.

    • If R1 is a reference type then:

      • R1 is either a subtype of R2 or R1 can be converted to a subtype of R2 by unchecked conversion (§5.1.9), or

      • R1 = |R2|

    ("|R2|" refers to the erasure of the type R2, as defined in §4.6 of the JLS.)


    * Prior to Java 5, Java had invariant return types, which meant the return type of a method override needed to exactly match the method being overridden.

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

Sidebar

Related Questions

Methods marked as virtual can be overridden in derived classes. One of the restrictions
For a math package, I am trying to have classes for different types of
I have an array of different objects with different data types I want to
I have a need for a dictionary with multiple keys of 2 different types
I have three classes that will each return a slightly different result. // interfact
I want to create a class that can take different types of value in
The method ObjectOutputStream.writeStreamHeader() can be overridden to prepend or append data to the header.
I'm not sure what it's called but you can override methods easily with: Apple
I know you can override delete and save methods in DJango models, but can
ObjC has a very unique way of overriding methods. Specifically, that you can override

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.