What is the difference between abstract class vs interface? Can give me the real time examples?
Answer / Sachin Bajpai
Abstract classes and interfaces are both used to achieve polymorphism in object-oriented programming, but they have some differences:
1. Method Implementation: Abstract classes can have concrete methods with implementation, whereas interfaces only define method signatures without implementation.
2. Inheritance: A class inherits from one abstract class, but can implement multiple interfaces.
3. Real-time example: Let's consider an example of a shape hierarchy where we have a Shape abstract class and two interfaces IPrintable and IResizable. The Shape abstract class could contain properties like Color and Name, while the IPrintable interface would define a Print() method and IResizable would define Resize() methods.
4. An example implementation might look something like this:
```csharp
public abstract class Shape
{
public string Color { get; set; }
public string Name { get; set; }
}
public interface IPrintable
{
void Print();
}
public interface IResizable
{
void Resize(int newSize);
}
public class Circle : Shape, IPrintable, IResizable
{
public double Radius { get; set; }
public void Print()
{
// Implementation of the print method for the circle shape
}
public void Resize(int newSize)
{
// Implementation of the resize method for the circle shape
}
}
```
| Is This Answer Correct ? | 0 Yes | 0 No |
What is the default authentication mode for asp.net?
What three Session State providers are available in ASP.NET 1.1? What are the pros and cons of each ?
How to register exception filter globally?
What is a Repeater Control and how does it works? and what is the diffrence b/w Gridview,datalist and repeater control?
What does postback mean?
What are the asp.net objects? is it application obects, cache objests etc. or is it state managements, web services etc?
What are client activated objects and server activated objects?
What is ViewState ? and how it is managed ?
what are the security certificates used in webservices?
What is Pre-Render event in ASP.NET?
How is the asp.net mvc architecture different from others? : asp.net mvc
How u refer webservices?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)