Fragile class problem is a problem of object oriented programing. Suppose we have two class first class is the parent and second class is the child class. In the child class we have inherited the parent class and both have two overloaded function means have same method name.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication8 { classProgram { staticvoid Main(string[] args) { Child obj = newChild(); int i = 100; obj.NumberNumeric(i); double j = 100; obj.NumberNumeric(j); } } publicclassParent { publicvirtualvoid NumberNumeric(int i) { Console.WriteLine("Parent Number Function"); } } publicclassChild : Parent { publicvoid NumberNumeric(double i) { Console.WriteLine("Child Number Function"); } } }
When we run this application we get unexpected result
To overcome this problem we can make the class sealed. In the above example I have make parent class and child and in the child I have extended parent class then in the main make the instance of child.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Fragile class problem is a problem of object oriented programing. Suppose we have two class first class is the parent and second class is the child class. In the child class we have inherited the parent class and both have two overloaded function means have same method name.
When we run this application we get unexpected result
To overcome this problem we can make the class sealed. In the above example I have make parent class and child and in the child I have extended parent class then in the main make the instance of child.