π Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
1. What is polymorphism in C#?
Answer:
Explanation:
Polymorphism in C# allows methods with the same name to behave differently in different classes, usually through method overriding.
2. Which keyword is used for method overriding in C#?
Answer:
Explanation:
The 'override' keyword is used in a derived class to override a method defined in the base class.
3. What is method overloading in C#?
Answer:
Explanation:
Method overloading involves creating multiple methods in the same class with the same name but different parameter lists.
4. What is required to make a method overridable in a base class in C#?
Answer:
Explanation:
To allow a method to be overridden in derived classes, it must be declared with the 'virtual' keyword in the base class.
5. How can you hide a method in a base class without overriding it in C#?
Answer:
Explanation:
The 'new' keyword can be used in a derived class to hide a non-virtual method of the base class.
6. What is dynamic polymorphism in C#?
Answer:
Explanation:
Dynamic polymorphism is determined at runtime, typically through method overriding, allowing objects to be treated as instances of their base type.
7. What happens when a virtual method is called on a reference whose compile-time type is different from its runtime type?
Answer:
Explanation:
When a virtual method is called, the version of the method that corresponds to the runtime type of the object is executed.
8. Can interfaces be used to achieve polymorphism in C#?
Answer:
Explanation:
Interfaces provide a way to achieve polymorphism in C# by defining a contract that can be implemented differently by multiple classes.
9. What is the difference between static and dynamic polymorphism?
Answer:
Explanation:
Static polymorphism (method overloading) is resolved at compile time, while dynamic polymorphism (method overriding) is resolved at runtime.
10. In C#, how do you prevent a method from being overridden in a derived class?
Answer:
Explanation:
The 'sealed' keyword is used on a method in a derived class to prevent further overriding of that method in any subsequent derived classes.
Comments
Post a Comment
Leave Comment