Explain what is an interface and what is an abstract class? Please, expand by examples of using both. Explain why?
Answer / Rohit Sachan
An interface defines a contract that a class must implement to inherit its members. It doesn't have any implementation itself and is used for polymorphism.nnExample: An IShape interface might define methods like Area() and Perimeter(), but doesn't provide an implementation:ntpublic interface IShape{nttdouble Area();nttdouble Perimeter();nt}nnA class implementing the IShape interface must provide its own implementation for each method defined in the interface.nnAn abstract class is a class that cannot be instantiated and serves as a base class for other classes. It may have some implemented methods, but it's usually used to define common properties or behavior that can be shared among multiple derived classes.nnExample: An abstract Shape class might define default implementations for Area() and Perimeter() methods and provide a concrete implementation for simple shapes like Circle and Rectangle:ntpublic abstract class Shape {nttprotected double _width; nttprotected double _height;nttpublic double Area() {ntttreturn _width * _height;ntt}nttpublic double Perimeter() {ntttthrow new NotImplementedException();ntt}nt}ntpublic class Circle : Shape {nttprotected double _radius;nttpublic override double Area() {ntttreturn Math.PI * (_radius * _radius);ntt}nttpublic override double Perimeter() {ntttreturn 2 * Math.PI * _radius;ntt}
| Is This Answer Correct ? | 0 Yes | 0 No |
What is .NET Framework?
What is UDDI and how to register the web service in it?
Do you know the difference between the stack and the heap?
What is the difference between a namespace and assembly name in .net?
What is garbage collection in .net? Explain the garbage collection process?
Explain the difference between public and static modifiers?
How does linq work?
What is common language specification (cls)?
asp mean
How do you generate a strong name?
What is managed code in .NET?
Can you write a class without specifying namespace?