Tell me about both
Loading
Tell me about both
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ajay BansodeRank #7,443 · 241 reputationPosted Jul 24, 2025, 1:41 PM EDT
Abstraction: Hides complexity by showing only essential features and hiding implementation details.
Inheritance: Enables code reuse by allowing a class to inherit members (fields, methods) from another class.
Hemant SrivastavaRank #581 · 4.2K reputationPosted Jul 25, 2025, 8:06 AM EDT
Abstraction
Abstraction hides the internal implementation details and shows only the necessary features of an object.
How it's done in C#:
Sample Code :
abstract class Animal
{
public abstract void MakeSound(); // Abstract method
}
class Dog : Animal
{
public override void MakeSound()
{
Console.WriteLine("Bark");
}
}
Animalis an abstract class that defines a contract.Dogprovides the actual implementation.--------------------
Inheritance:
Inheritance allows a class to inherit members (fields, methods, properties) from another class.
How it's done in C#:
:symbol to derive a class from a base class.Sample Code:
class Animal
{
public void Eat()
{
Console.WriteLine("This animal eats food.");
}
}
class Dog : Animal
{
public void Bark()
{
Console.WriteLine("Dog barks.");
}
}
Doginherits theEat()method fromAnimal.Deepak TewatiaRank #143 · 15.9K reputationPosted Jul 14, 2025, 1:34 PM EDT
Read more here :- https://www.c-sharpcorner.com/article/oops-concepts-and-net-part-2-inheritance-abstraction-and/