Loading
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
Vijay KumariRank #61 · 27.6K reputationPosted May 27, 2025, 8:14 AM EDT
Inheritance is an object-oriented concept that lets a derived class reuse (inherit) the fields, properties, and methods of a base class, promoting code reusability and a clear class hierarchy. In .NET you get:
Code Example
using System; namespace InheritanceDemo { // Base class public class Animal { public string Name { get; set; } // Virtual method allows overriding in derived classes public virtual void Speak() { Console.WriteLine($"{Name} makes a sound."); } } // Derived class public class Dog : Animal { // Override the virtual method public override void Speak() { Console.WriteLine($"{Name} says: Woof!"); } // New method specific to Dog public void Fetch() { Console.WriteLine($"{Name} is fetching the ball!"); } } class Program { static void Main(string[] args) { // Instantiate derived class Dog myDog = new Dog { Name = "Buddy" }; // Calls overridden method myDog.Speak(); // Output: Buddy says: Woof! // Calls method defined only in Dog myDog.Fetch(); // Output: Buddy is fetching the ball! // Polymorphism: base-class reference to a derived instance Animal pet = new Dog { Name = "Charlie" }; pet.Speak(); // Output: Charlie says: Woof! } } }Deepak TewatiaRank #143 · 15.9K reputationPosted May 27, 2025, 2:44 AM EDT
One class can take features from another class.
Kiran KumarRank #1,268 · 1.4K reputationPosted May 28, 2025, 5:38 AM EDT
Hi Vijaya got it thanks but can you provide some good example since I am implementing financial application , for Banking application can I use this feature