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

  • Home
  • SEARCH
  • 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 7587563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:42:17+00:00 2026-05-30T19:42:17+00:00

interface A { public void m1(); } **//Gives error** class D implements A {

  • 0
 interface A { public void m1(); }
 **//Gives error**
   class D implements A { public void m1(int x) { } }
 **//this doen't** 
 abstract class G implements A { public void m1(int x) { } }

I have a doubt that why abstract class is able to override and class D can’t

If I see the second case

 class X1
{
 public void f2(){}
 }

class X2 extends X1
 {**//No error**
  public void f2(int x){}
}

why public void m1() is not getting overidden in class D whereas same type of method f2() is getting overriden in class X2
In both cases we are overidding but why in interface case class D cant and in second case class X2 can override.

  • 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-30T19:42:18+00:00Added an answer on May 30, 2026 at 7:42 pm

    When there are two methods with the same name but different parameter types (or counts), that’s overloading, not overriding.

    • D doesn’t implement A itself because it doesn’t provide an implementation of m1() – no parameters. It tries to provide a method m1(int), but that doesn’t help to implement the interface – so it won’t compile (as it’s not an abstract class). It could provide both methods of course.
    • X1 provides a method f2(), and X2 extends X1 and adds a new overload f2(int) – but it doesn’t override the method provided by X1.

    In particular, if you write:

    X2 x2 = new X2();
    x2.f2(10); // Calls X2.f2(int)
    x2.f2(); // Calls X1.f2()
    

    Using the @Override annotation makes all of this clearer:

    class X1
    {
         public void f2(){}
    }
    
    class X2 extends X1
    {
         @Override public void f2(int x){}
    }
    

    This now gives an error:

    error: method does not override or implement a method from a super type
         @Override public void f2(int x){}
         ^
    1 error
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So lets say I have this interface: public interface IBox { public void setSize(int
For example public interface X{ public void foo(X i); } public class Y implements
interface A { void hi(); } class AImpl implements A { public void hi()
I have this interface: public interface IValidationCRUD { public ICRUDValidation IsValid(object obj); private void
Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)
Consider I have the following interface: public interface A { public void b(); }
I have an interface method public void Execute(ICommand command); which needs to pass known
I have the following code: import com.apple.dnssd.*; public interface IServiceAnnouncer { public void registerService();
public interface ITest { void Somethink(); } public class Test1 : ITest { public
Basically I want to do this: public interface A { void a(); } public

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.