Frequently Asked Interview Questions

Interview questions on Abstract Class and Interface

Interview questions on Abstract Class and Interface
Abstract class is a class that can not be instantiated. The derived classes must provide implementation for all abstract methods defined in Abstract class.
NO
No, we can have Abstract class without abstract method.
Yes
No, Virtual or Abstract members can not be declared as private.
Yes, You can define data and member fields.
Interface is a contract it defines the signature of the functionality. If any class is implementing an interface that should provide implementation for all the methods defined in Interface.
Yes, Class can implement multiple interfaces.
Please answer the following questions.

  • Will it be an Issue? No
  • Do I need to implement two different Add () methods? If yes how can you implement in derived class?Yes, we need to provide the implementation for two Add() methods by prefixing Interface name to method name. The implementation would be like this:Interface1.Add() {------} and Interface2.Add() {-----}
  • How can you access a specific Add() method of a class?

    Interface1 obj1= new Derrivedclass();
    Obj1.Add() //Invoke the Interface1.Add() Method.


    Interface2 obj2= new Derrivedclass();
    Obj2.Add() //Invoke the Interface2.Add() Method.

Most Visited Pages

Home | Site Index | Contact Us