Here one more basic question asked in MS interview recently
class A {
public virtual void Method1(){}
public void Method2() {
Method1();
}
}
class B:A {
public override void Method1() { }
}
class main {
A obk = new B();
obk.Method2();
}
So which function gets called? Sorry for the typos.
In computer science, polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface. According to that definition, no, C doesn't natively support polymorphism.
C is a Procedural Oriented language. It does not support object-oriented programming (OOP) features such as polymorphism, encapsulation, and inheritance programming.
The word “polymorphism” means having many forms. In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. A real-life example of polymorphism is a person who at the same time can have different characteristics.
There are two major types of polymorphisms in Object Oriented Programming (OOPS) languages. They are Static Binding (Compile time Polymorphism) and Dynamic Binding (Runtime Polymorphism). Method overriding would be the example of Dynamic Polymorphism and Method Overloading would be the example of Static Polymorphism.
B.Method1();
gets called because it properly overrides the virtual method A.Method1();
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