My Report

C# Interface Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following C# code?

 
 interface calc
 {
     void cal(int i);
 }
 class displayA :calc 
 {
     public int x;
     public void cal(int i) 
     {
         x = i * i;            
     }
 }
 class displayB :calc
 {
     public int x;
     public void cal(int i)
     {
         x = i / i;
     }
 }
 class Program
 {
     public static void Main(string[] args)
     {            
         displayA arr1 = new displayA();
         displayB arr2 = new displayB();
         arr1.x = 0;
         arr2.x = 0;
         arr1.cal(2);
         arr2.cal(2);
         Console.WriteLine(arr1.x + " " + arr2.x);
         Console.ReadLine();
     }
 }

2. What will be the Correct statement in the following C# code?

 interface abc
 {
     String FirstName
     {
         get;
         set;
     }
    String LastName
    {
        get;
        set;
    }
    void print();
    void stock();
    int fun();
}

3. What will be the Correct statement in the following C# code?

interface a1
{
    void f1();
    int f2();
}
class a :a1
{
    void f1()
    {
    }
    int a1.f2()
    {
    }
}

4. Choose the wrong statement about 'INTERFACE' in C#.NET?

5. What will be the output of the following C# code?

 
 interface calc
 {
     void cal(int i);
 }
 public  class maths :calc 
 {
     public int x;
     public void cal(int i) 
     {
         x = i * i;            
     }
 }
 class Program
 {
     public static void Main(string[] args)
     {            
         display arr = new display();
         arr.x = 0;      
         arr.cal(2);
         Console.WriteLine(arr.x);
         Console.ReadLine();
     }
 }

6. 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 C# codes is?

7. What will be the output of the following C# code?

 
interface i1
{
    void fun();
}
interface i2
{
    void fun();
}
public class maths :i1, i2
{
    void i1.fun()
    {
        Console.WriteLine("i1.fun");
    }
    void i2.fun()
    {
        Console.WriteLine("i2.fun");
    }
}
class Program
{
    static void Main(string[] args)
    {
        Sample obj = new Sample();
        i1 i = (i1) obj;
        i.fun();
        i2 ii = (i2) obj;
        ii.fun();
    }
}

8. What will be the Correct statement in the following C# code?

 interface a1
 {
     void f1();
     void f2();
 }
 class a :a1
 { 
     private int i;
     void a1.f1()
     {
     }
 }

9. What will be the correct way to implement the interface in the following C# code?

  interface abc
   {
       string name
       {
           get;
           set;
       }
   }

10. What will be the output of the following C# code?

 
 interface i1
 {
     void f1();
 }
 interface i2 :i1
 {
     void f2();
 }
 public class maths :i2
 {
     public void f2()
     {
         Console.WriteLine("fun2");
     }
     public void f1()
     {
         Console.WriteLine("fun1");
     }
 }
 class Program
 {
     static Void Main()
     {
         maths m = new maths();
         m.f1();
         m.f2();
     }
 }

 

Start practicing “1000 MCQs on C#”, and once you are ready, you can take tests on all topics by attempting our “C# Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.