C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Class with multiple interface-inheritance and interfaces with same method name&signature?


Posted Date: 29 Aug 2008      Total Responses: 1

Posted By: Hari       Member Level: Silver     Points: 1


Hi,

Please clarify my doubt:
I have 2 interfaces interface1,interface2 both the interfaces having the same method with the same signature.say,

interface Interface1
{
int add();
}
interface Interface2
{
int add();
}
class MultipleInheritance:Interface1,Interface2
{
int add()
{
return 10+20;
}
}

Whether class will get compile or not?
If it will not compile what error it will give...?and why?
If it will compile, can you explain me,why?






Responses

Author: J Ramesh    29 Aug 2008Member Level: SilverRating:     Points: 6
Hi Hari,

The code as such will not get compiled and will return these errors

Class1 does not implement interface member 'Application1.Interface1.Add()'. 'Application1.Class1.Add()' is either static, not public, or has the wrong return type.

Class1 does not implement interface member 'Application1.Interface2.Add()'. 'Application1.Class1.Add()' is either static, not public, or has the wrong return type.

In order to use the same you need to implement the code like this

public class Class1:Interface1,Interface2
{
int Interface1.Add()
{
return 10 + 20;
}
int Interface2.Add()
{
return 1 + 2;
}
}

This way the code will get complied and you will not get any errors.

Even incase of using just a single interface you need to give the Interfacename.Methodname for the code to get compiled.

Regards
Ramesh



Post Reply
You must Sign In to post a response.
Next : advanced search in C# ---- begin ASP
Previous : Metadata
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

conference calls

Contact Us    Privacy Policy    Terms Of Use