C# Questions & Answers on Interfaces Implementation for Freshers

1. Correct statement about c#.NET code snippet given below is?
  1. interface a1
  2. {
  3.     void f1();
  4.     int f2();
  5. }
  6. class a :a1
  7. {
  8.     void f1()
  9.     {
  10.     }
  11.     int a1.f2()
  12.     {
  13.     }
  14. }
a) class a is an abstract class
b) A method table would not be created for class a
c) The definition of f1() in class a should be void a1.f1()
d) None of the mentioned
View Answer
Answer: c
Explanation: None.
2. Choose the wrong statement about ‘INTERFACE’ in C#.NET?
a) An explicitly implemented member could be accessed from an instance of the interface
b) Interfaces are declared public automatically
c) An interface could not contain signature of the indexer
d) None of the mentioned
View Answer
Answer: c
Explanation: None.
3. Choose the correct statement about following code snippet given below:
  1.  interface a1
  2.  {
  3.      void f1();
  4.      void f2();
  5.  }
  6.  class a :a1
  7.  { 
  8.      private int i;
  9.      void a1.f1()
  10.      {
  11.      }
  12.  }
a) Class a could not have an instance data
b) Class a is an abstract class
c) Class a fully implements the interface a1
d) None of the mentioned
View Answer
Answer: b
Explanation: None.
4. Choose the correct statement about the following code snippet in C#.NET:
  1.  interface abc
  2.  {
  3.      String FirstName
  4.      {
  5.          get;
  6.          set;
  7.      }
  8.     String LastName
  9.     {
  10.         get;
  11.         set;
  12.     }
  13.     void print();
  14.     void stock();
  15.     int fun();
  16. }
a) Functions should be declared inside an interface
b) It is workable code
c) Properties cannot be declared inside an interface
d) None of the mentioned
View Answer
Answer: b
Explanation: None.
5. What will be the output of the given code snippet?
  1.  interface calc
  2.  {
  3.      void cal(int i);
  4.  }
  5.  public  class maths :calc 
  6.  {
  7.      public int x;
  8.      public void cal(int i) 
  9.      {
  10.          x = i * i;            
  11.      }
  12.  }
  13.  class Program
  14.  {
  15.      public static void Main(string[] args)
  16.      {            
  17.          display arr = new display();
  18.          arr.x = 0;      
  19.          arr.cal(2);
  20.          Console.WriteLine(arr.x);
  21.          Console.ReadLine();
  22.      }
  23.  }
a) 0
b) 2
c) 4
d) None of the mentioned
Answer: c
Output : 4
6. What will be the output of the given code snippet?
  1.  interface calc
  2.  {
  3.      void cal(int i);
  4.  }
  5.  class displayA :calc 
  6.  {
  7.      public int x;
  8.      public void cal(int i) 
  9.      {
  10.          x = i * i;            
  11.      }
  12.  }
  13.  class displayB :calc
  14.  {
  15.      public int x;
  16.      public void cal(int i)
  17.      {
  18.          x = i / i;
  19.      }
  20.  }
  21.  class Program
  22.  {
  23.      public static void Main(string[] args)
  24.      {            
  25.          displayA arr1 = new displayA();
  26.          displayB arr2 = new displayB();
  27.          arr1.x = 0;
  28.          arr2.x = 0;
  29.          arr1.cal(2);
  30.          arr2.cal(2);
  31.          Console.WriteLine(arr1.x + " " + arr2.x);
  32.          Console.ReadLine();
  33.      }
  34.  }
a) 0 0
b) 2 2
c) 4 1
d) 1 4
Answer: c

Explanation: class displayA executes the interface calculate by doubling the value of item . Similarly class displayB implements the interface by dividing item by item.So, variable x of class displayA stores 4 and variable x of class displayB stores 1.
Output : 4, 1
7. Choose the correct output of the given code snippet?
  1. interface i1
  2. {
  3.     void fun();
  4. }
  5. interface i2
  6. {
  7.     void fun();
  8. }
  9. public class maths :i1, i2
  10. {
  11.     void i1.fun()
  12.     {
  13.         Console.WriteLine("i1.fun");
  14.     }
  15.     void i2.fun()
  16.     {
  17.         Console.WriteLine("i2.fun");
  18.     }
  19. }
  20. class Program
  21. {
  22.     static void Main(string[] args)
  23.     {
  24.         Sample obj = new Sample();
  25.         i1 i = (i1) obj;
  26.         i.fun();
  27.         i2 ii = (i2) obj;
  28.         ii.fun();
  29.     }
  30. }
a) i1.fun
b) i2.fun
i1.fun
c) 0
d) i1.fun
i2.fun
Answer: d
8. Correct way to implement the interface given below?
  1.   interface abc
  2.    {
  3.        string name
  4.        {
  5.            get;
  6.            set;
  7.        }
  8.    }
a)
   class emp :employee
   {
       private string str;
       public string firstname;
       {
           get
           {
               return str;
           }
           set
           {
               str = value;
           }
       }
   }
b)
  class emp :implements person
  {
      private string str;
      public string firstname
      {
          get
          {
              return str;
          }
          set
          {
              str = value;
          }
      }
  }
c)
 class emp: implements person
 {
     private string str;
     public string person.firstname
     {
         get
         {
             return str;
         }
         set
         {
             str = value;
         }
     }
 }
d) None of the mentioned
Answer: a
9. Choose the correct output of the following code snippet?
  1.  interface i1
  2.  {
  3.      void f1();
  4.  }
  5.  interface i2 :i1
  6.  {
  7.      void f2();
  8.  }
  9.  public class maths :i2
  10.  {
  11.      public void f2()
  12.      {
  13.          Console.WriteLine("fun2");
  14.      }
  15.      public void f1()
  16.      {
  17.          Console.WriteLine("fun1");
  18.      }
  19.  }
  20.  class Program
  21.  {
  22.      static Void Main()
  23.      {
  24.          maths m = new maths();
  25.          m.f1();
  26.          m.f2();
  27.      }
  28.  }
a) fun2
b) fun1
c) fun1
fun2
d) fun2
fun1
Answer: c
10. In order to avoid ambiguity among an interface derived from two base interfaces with same method name(and signature), the right code among the following given codes is?
a)
  1.  interface i1
  2.  {
  3.      void m1();
  4.  }
  5.  interface i2
  6.  {
  7.      void m1();
  8.  }
  9.  interface i3 :i1, i2
  10.  {
  11.  }
  12.  class c3 :i3
  13.  {
  14.      void i1.m1()
  15.      {
  16.      }
  17.      void i1.m1()
  18.      {
  19.      }
  20.  }
b)
 interface i1
 {
     void m1();
 }
     interface i2
     {
         void m1();
     }
     interface i3 :i1, i2
     {
     }
     class c3 :i3
     {
         void i1.i2.m1()
         {
         }
     }
c)
  interface i1
  {
      void m1();
  }
  interface i2
  {
      void m1();
  }
  interface i3 :i1, i2
  {
  }
  class c3 :i3
  {
      void i1.m1()
      {
      }
      void i2.m1()
      {
      }
  }
d) All of the mentioned
Answer: c

Related

Multiple Choice Questions 5948842159379116568

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item