interface methods always virtual?

F

Fuzzy

If an object implements an interface, are interface methods always
virtual or only if accessed through the interface?

For example, if I have:

interface IFoo
{ public void Method1() }

and I have:
class Bar : IFoo
{
public void Method1(){} // IFoo method
public void Method2(){}
}

test code..

IFoo itfRef;
IBar objRef = new Bar();
itfRef = (IFoo)objRef;

itfRef.Method1(); // is a virtual call
objRef.Method1(); // ??
objRef.Method2(); // not a virtual call

Is objRef.Method1() also a virtual call or is this a direct call?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top