Click here to Skip to main content
15,910,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can a class implements an interface and an abstract class
Posted

Yes...

C#
public class MyClass : SomeAbstractClass, ISomeInterface
{

    public override int AbstractMethodNeedsImplementation()
    {
        return 10;
    }

    #region ISomeInterface Implementation

    public void SomeMethod()
    {
    }
    
    #endregion

}
 
Share this answer
 
YES U CAN Do THAT
 
Share this answer
 
Yes. Any concrete subclass will have to implement the abstract methods, so they will be implemented by the time any JVM is asked to invoke the method. It's just a special case of implementing by forcing subclasses to implement for you.

Your abstract class doesn't even have to mention the methods in the interface it 'implements', e.g. the following:-

interface SomeInterface {  
   void foo();  
   int  bar();  
}  
public abstract class YourClass implements SomeInterface {  
   // no mention of foo() and bar() here  
}

is perfectly legal. If a subclass of YourClass wants to be concrete class, it has to implement both foo() and bar().

I hope this clears your confusion.

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900