91) What is overriding in c# ?
To override a base class method which is defined as virtual, Override keyword is used. In the above example, method DriveType is overridden in the derived class.
class Car { public void DriveType() { Console.WriteLine("Right Hand Drive"); } } class Ford : Car { public void DriveType() { Console.WriteLine("Right Hand "); } }
93) What is Abstract Class in C#?
abstract class Car { public Car() { Console.WriteLine("Base Class Car"); } public abstract void DriveType(); } class Ford : Car { public void DriveType() { Console.WriteLine("Right Hand "); } }
94) What is Sealed Classes in c# ?
public sealed class Car { public Car() { Console.WriteLine("Base Class Car"); } public void DriveType() { Console.WriteLine("Right Hand "); } }
95) What is an Interface in C# ?
An interface is similar to a class with method signatures. There wont be any implementation of the methods in an Interface. Classes which implement interface should have an implementation of methods defined in the abstract class.
96) What is a Constructor in C# ?
Constructor is a special method that get invoked/called automatically, whenever an object of a given class gets instantiated. In our class car, constructor is defined as shown below
public Car() { Console.WriteLine("Base Class Car"); }
When ever an instance of class car is created from the same class or its derived class(Except Few Scenarios), Constructor get called and sequence of code written in the constructor get executed.
interface Breaks { void BreakType(); } interface Wheels { void WheelType(); } class Ford : Breaks, Wheels { public Ford() { Console.WriteLine("Derived Class Ford"); } public void Price() { Console.WriteLine("Ford Price : 100K $"); } public void BreakType() { Console.WriteLine("Power Break"); } public void WheelType() { Console.WriteLine("Bridgestone"); } }
97) What is a Destructor in C# ?
Destructor is a special method that get invoked/called automatically whenever an object of a given class gets destroyed. Main idea behind using destructor is to free the memory used by the object.