We created an interface III, which has only one function named PQR. Then, the class YYY implements Interface III, but does not implement the function PQR, but instead adds a function called ABC. In the entry point function Vijay, the function PQR is called by Interface III.
We did not get any errors because of the existence of the override directive. This instruction notifies the compiler to redirect any calls to the function PQR of interface III and to the function ABC of the class yyy. The compiler is very strict with the override instructions. This can be considered from the fact that if III is not implemented in the definition of class yyy, then we get the following exception:
Output
Exception Occurred:System.TypeLoadException:Class yyy tried to override method PQR but does not implement or inherit tha T methods.
At Zzz.vijay ()
destructor
A.cs
class zzz
{
public static void Main()
{
}
~zzz()
{
System.Console.WriteLine("hi");
}
}
A.il
.assembly mukhi {}
.class private auto ansi zzz extends [mscorlib]System.Object
{
.method public hidebysig static void vijay() il managed
{
.entrypoint
ret
}
.method family hidebysig virtual instance void Finalize() il managed
{
ldstr "hi"
call void [mscorlib]System.Console::WriteLine(class System.String)
ldarg.0
call instance void [mscorlib]System.Object::Finalize()
ret
}
}
No output