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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:55:06+00:00 2026-05-30T15:55:06+00:00

Suppose I have an interface called Interface, and a concrete class called Base, which,

  • 0

Suppose I have an interface called Interface, and a concrete class called Base, which, to make thing a bit more complicated, has a ctor that requires some arguments.

I’d like to create an anonymous class that would extend Base and implement Interface.

Something like

 Interface get()
 {
     return new Base (1, "one") implements Interace() {};
 }

That looks reasonable to me, but it doesn’t work!

(P.S: Actually, the Interface and Base are also generic classes :D. But I’ll ignore that for now)

  • 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-30T15:55:07+00:00Added an answer on May 30, 2026 at 3:55 pm

    This scenario makes little sense to me. Here’s why: assume class Base is this:

    class Base {
        public void foo();
    }
    

    and Interface is this:

    interface Interface {
        public void bar();
    }
    

    Now you want to create an anonymous class that would be like this:

    class MyClass extends Base implements Interface {
    }
    

    this would mean that MyClass inherits (or possibly overrides) method bar from Base and must implement method foo from Interface. So far so good, your class has these two methods either way.

    Now, think what happens when you are returning an object of type Interface from your method: you only get the functionality that Interface offers, namely method foo. bar is lost (inaccessible). This brings us down to two cases:

    1. Extending Base is useless because you do not get to use its methods, since the new object is seen as an Interface.
    2. Interface also has a method foo, but that would mean that Base itself should implement Interface, so you can just extend Base directly:
    class Base implements Interface {
        public void foo();
        public void bar();
    }
    
    class MyClass extends Base {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have Objective C interface SomeClass which has a class method called someMethod
Suppose we have: interface Foo { bool Func(int x); } class Bar: Foo {
Suppose we have a class called AccountService that manages the state of accounts. AccountService
Suppose I have this interface public interface IFoo { ///<summary> /// Foo method ///</summary>
Suppose I have two classes with the same interface: interface ISomeInterface { int foo{get;
Suppose I have a few definitions like so: public interface ICategory { int ID
Suppose I have created a UIView , MyView , in Interface Builder, and I
Suppose I'm implementing an MVP pattern and I have a view interface as such:
Suppose i have a interface like this, interface MyIntf{ void generate(); } and a
Suppose I have a simple interface representing a complex number, whose instances would be

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.