Method Overloading

Method overloading allows a class to have multiple methods with the same name but different parameter lists. It's a way of increasing the readability of the program by having a single method name perform similar actions based on different input parameters.


                            public class Calculator {
                                // Overloaded Add method with two integer parameters
                                public int Add(int a, int b) {
                                    return a + b;
                                }

                                // Overloaded Add method with two double parameters
                                public double Add(double a, double b) {
                                    return a + b;
                                }
                            }
                        

Method Overriding

Method overriding is a feature that allows a subclass to provide a specific implementation of a method that is already defined in its superclass. The method in the subclass must have the same name, return type, and parameters as the one in its superclass.


                            public class Animal {
                                public virtual void Speak() {
                                    Console.WriteLine("The animal speaks.");
                                }
                            }

                            public class Dog : Animal {
                                public override void Speak() {
                                    Console.WriteLine("The dog barks.");
                                }
                            }

                            public class Cat : Animal {
                                public override void Speak() {
                                    Console.WriteLine("The cat meows.");
                                }
                            }