Interface-Abstract class – C# Programming Interview Questions

This section contains real OOP C# programming interview questions and answers on C# interfaces and abstract class asked in C# technical interviews to IT professionals. Answers to questions are provide with example and explanation. Also, these technical job interview questions and answers will boost the concept on C# Interface and Abstract class programming.

Topic – Interface, implicit and explicit interface, Abstract class etc.


Q – Write complete program for below scenario in C#.

Interview Question Scenario: Crate a class Travel Insurance using below Interface and call GetInsurance() method in main() program.

interface Insurance
{
void GetInsurance();
}

Answer: To use the interface, a Travel Insurance class need to be derived from Insurance Interface and implement GetInsurance() method.

interface Insurance
{
    void GetInsurance();
}

//Crate TravelInsurance class and derived from Insurance Interface
class TravelInsurance:Insurance
{
    //Implement GetInsurance() method of Insurance Interface.
    public void GetInsurance()
    {
        Console.WriteLine("Travel Insurance");
    }
}

class Program
{
    static void Main(string[] args)
    {
        //Crate Insurance interface referance and assign
        //Object of TravelInsurance class.
        Insurance ti = new TravelInsurance();
        //Call method.
        ti.GetInsurance();

    }
}


Related Posts