Is it possible to call a method in implementation class of an interface which is not defined in interface using interface variable like below:
interface ILookup {
public void someInterfaceMethod1();
public void someInterfaceMethod2();
}
...and implementation class:
public class extendedLookUpImplementor: ILookup
{
//constructor
LookUpImplementor(){
}
public void someInterfaceMethod1(){
// Implementation Code here.
}
public void someInterfaceMethod2(){
// Implementation Code here.
}
public void ExtendedMethod(){
// Implementation Code here.
}
}
In client code:
ILookup lookupVar = new LookUpImplementor();
lookupVar -> someInterfaceMethod1(); // i know it will work.
lookupVar -> someInterfaceMethod2(); // i know it will work.
My question is, can i call ExtendedMethod using lookupVar like below:
lookupVar -> ExtendedMethod(); // Note again that ExtendedMethod() is not defined in Ilookup interface/contract.
Only by casting lookupVar as extendedLookUpImplementor, or by reflection I think.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With