Select chapter



Basics (2.papers)
Data Types (2.papers)
enums (2.papers)
OOPS (4.papers)
Arrays (1.papers)
Structs (2.papers)
Properties (2.papers)
Strings (2.papers)
Interfaces (1.papers)
Constructors (2.papers)
Ref-Out-Keywords (1.papers)
Collections (2.papers)
Generics (1.papers)
Hide

Sponsored Links


  

c# interfaces interview questions and answers

1
What is an interface in C# ?
  1. An interface in C#  contains only signatures of methods, properties, events and indexers but not implementations.
  2. An interface in C# cannot contain data members or variable declarations but only un-implemented methods are allowed.
  3. An interface is similar to a class with un-implemented methods and no data members or variables are allowed including constants and read only variables . For an interface we cannot create an instance or an object.
  4. All the above options are correct.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
3
Which of the following is the correct implementation of the given  interface?
public interface IEmployee
{ 
    double Salary(float f);
}
  1. public class Employee:IEmployee
    {
      public double IEmployee.Salary(float f);
    }
  2. public class Employee:IEmployee
    {
      public double IEmployee.Salary(float f){}
    }
  3. public class Employee:IEmployee
    {
      double IEmployee.Salary(float f){ return  10.678 ; }
    }
  4. public class Employee:IEmployee
    {
      double IEmployee.Salary(float f);
    }
Show Answer
Share Facebook gmail Twitter
4
Which of the following statement is not true about an interface?
  1. An interface can inherit from another interface.
  2. An interface can inherit from multiple interfaces.
  3. A class can implement multiple interfaces.
  4. It is possible to create a run-time instance of an interface.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
6
Which of the following statement is not true about an interface used in C#.NET?
  1. A class or a struct can implement one or more interfaces.
  2. An interface can contain un-implemented properties, methods and events.
  3. An enum can implement an interface.
  4. An interface itself  can inherit from multiple other interfaces.
Show Answer
Share Facebook gmail Twitter
7
Which of the following statements is correct about the given Interface?
public interface IStudent
{ 
      int this[int i] { get; }
}
  1. The given code will compile and run without any errors or exceptions.
  2. Indexers cannot be declared inside an interface.
  3. The get accesor inside indexers in the interface must have a body.
  4. Indexers must have a access modifier.
Show Answer
Share Facebook gmail Twitter
8
Which of the following statements is true about the given C# code?
public interface ISample
{ 
    void M1(); 
    int M2();
}
public class Sample: ISample
{ 
    void M1() { } 
    int ISample.M2() { return 999;} 
}
  1. Sample class must be declared as an abstract class.
  2. The definition of M1() in class Sample should be void ISample.M1().
  3. The definition of M1() and M2() in class Sample should be public
  4. The definition of M1() in class Sample should be abstract
Show Answer
Share Facebook gmail Twitter
9
How to implement an interface in C# ( identify the correct way of implementing below given interface ) ?
public interface IEmployee
{
    double Salary(float f);
}
  1. public class Employee:IEmployee
    {
      public abstract double Salary(float f);
    }
  2. public abstract class Employee:IEmployee
    {
      public abstract double Salary(float f);
    }
  3. public abstract class Employee:IEmployee
    {
      public virtual double Salary(float f);
    }
  4. none of the above
Show Answer
Share Facebook gmail Twitter
10
Which of the following is the correct way to implement the interface given below?
Public interface IStudent
{ 
    int StudentId { get;set; } 
}
  1. public class Student implements IStudent
    {
        private int sid; 
        public int StudentId
        {
            get
            { 
                return sid
            } 
            set
            { 
                sid = value;
            } 
        } 
    }
  2. public class Student : IStudent
    {
        private int sid; 
        public int StudentId
        {
            get
            { 
                return sid
            } 
            set
            { 
                sid = value;
            } 
        } 
    }
  3. public class Student :IStudent
    {
        private int sid; 
        public int  Student.StudentId
        {
            get
            { 
                return sid
            } 
            set
            { 
                sid = value;
            } 
        } 
    }
  4. we can not declare properties in Interfaces.
Show Answer
Share Facebook gmail Twitter
11
Which of the following statement is true about an interface ?
  1. All interfaces are derived from an Object interface.
  2. An interface can contain  constant declaration using "const" keyword.
  3. A class can implement an interface members partially.
  4. An interface can contain readonly variables.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
14
Which of the following statement is true about given code?
namespace Skillgun
{
    public interface ICalc
    {
         int Add(int x,int y);      
    }
    public class Calc :ICalc
    {
        int  ICalc.Add(int x,int y)
        {
            return x + y;
        }                
    }
    public class Test
    {
        public static void Main()
        {
            Calc c = new Calc();
            int y = c.Add(10, 20);
        }
    }
}
  1. Code will compile without any errors.
  2. Definition of Add(int,int) in Calc class should be public.
  3. Compilation error, since we must call the Add(int,int) by using reference variable of Icalc interface Type.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
17
Which of the below given option is suitable for implementing interface I1,I2 in  a "Test" class ?
public interface I1
{
    int M(int x, int y);
}
public interface I2
{
    int M(int x, int y);
}
  1. Implement I1,I2 interfaces in Test class using implicit implementation technique.
  2. Implement I1,I2 interfaces in Test class using explicit implementation technique.
  3. It is not possible to give implementation for I1,I2 in Test class since both the interfaces having same method with the name M.
  4. None of the given options are suitable.
Show Answer
Share Facebook gmail Twitter
18
Which of the following keywords or symbols used for implementing and inhering the base members in C# ?
  1. implements, extends
  2. use symbol ":"  for implementing as well as inheriting in c#.
  3. Both the options are valid.
  4. None of the options are valid.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Read more papers :