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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:48:02+00:00 2026-06-04T16:48:02+00:00

I have written a class which is a base class of Class A and

  • 0

I have written a class which is a base class of Class A and implements an interface of Class B.

Now my compiler is giving a wierd kind of error saying that “The return types of functiona from Class A is not compatible with return type of functiona in class B.”

My Code is as below,

public class X extends A implements B
{
}

public class A
{
  public Enumeration<String> test(){}
}

public interface B
{
  public Enumeration<Object> test();
}

Now I can’t understand why the compiler is giving such an error since already String is a type of an object, so what i understood is that automatic type conversion should happen in runtime because of that. Am i right? or my conceptual understanding has gone wierd on me?

  • 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-04T16:48:03+00:00Added an answer on June 4, 2026 at 4:48 pm

    What you’re trying to do is possible in Java. As Ernest stated, an Enumeration is not a subclass of Enumeration, since Java genercis lacks the concept of variance.

    Anyway, you can express you intention using type wildcard. You have to change you interface this way:

    public interface B
    {
      public Enumeration<?> test();
    }
    

    Now your code compile fine. Just to let you know, you can also restrict your interface to some other type than Object. For example, if you have to build an interface that return Enumerations
    of Number:

        class X extends A implements B
        {
        }
    
        class A
        {
            public Enumeration<Long> test(){return null;}
        }
    
        class C
        {
            public Enumeration<String> test(){return null;}
        }
    
        //This doesn't compile! String does not extend Number
        /*class Y extends C implements B
        {
        }*/
    
        interface B
        {
            public Enumeration<? extends Number> test();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a base class from which I wish to derive several child
I have written a class in python that implements __str__(self) but when I use
I have written a class that will handle internal logging in my application. Now
I have written the following class which implements(or tries to!) a dictionary with notifications:
I have a base class (written using C#.net) which uses datasets to pull data
I have written an NHibernateSessionFactory class which holds a static Nhibernate ISessionFactory. This is
I have written an Apex class in a Salesforce managed package which uses the
I have a class written in c# which is acting as a wrapper around
I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
I have an object of class Message, which can be written and subsequently updated.

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.