How does VB.NET/C# achieve polymorphism?

Answer Posted / deep

Polymorphism is also achieved through interfaces. Like abstract classes, interfaces also describe the methods that a class needs to implement. The difference between abstract classes and interfaces is that abstract classes always act as a base class of the related classes in the class hierarchy. For example, consider a hierarchy-car and truck classes derived from four-wheeler class; the classes two-wheeler and four-wheeler derived from an abstract class vehicle. So, the class 'vehicle' is the base class in the class hierarchy. On the other hand dissimilar classes can implement one interface. For example, there is an interface that compares two objects. This interface can be implemented by the classes like box, person and string, which are unrelated to each other.

C# allows multiple interface inheritance. It means that a class can implement more than one interface. The methods declared in an interface are implicitly abstract. If a class implements an interface, it becomes mandatory for the class to override all the methods declared in the interface, otherwise the derived class would become abstract.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the main advantages of using asp.net?

760


How can we use Web API with ASP.NET Web Form?

817


Is asp.net and .net same?

728


What is rich control in asp.net?

725


What is the difference between exe and dll?

798


What is globalization and localization in asp net?

707


What are early binding and late binding.

821


How can we prevent browser from caching an aspx page?

699


What is difference between viewstate and session in asp net?

763


What is the caspol.exe tool used for?

746


What is sql data source control in asp.net?

787


Explain the difference between response.redirect vs server.transfer

860


What is data reader in asp.net?

749


what are configuration files?

737


What is the difference between stored procedure vs function?

777