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?
|
| Author: J Ramesh 29 Aug 2008 | Member Level: Silver | Rating: 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
|