My Report

C# Overloading 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?

class maths
{
    int i;
    public maths(int x)
    {
        i = x;
        Console.WriteLine(" hello: ");
    }
}
class maths1 : maths
{
    public  maths1(int x) :base(x)
    {
        Console.WriteLine("bye");
    }
}
class Program
{
    static void Main(string[] args)
    {
        maths1 k = new maths1(12);
        Console.ReadLine();
    }
}

2. When we call a constructor method among different given constructors. We match the suitable constructor by matching the name of constructor first, then the number and then the type of parameters to decide which constructor is to be overloaded. The process is also known as?

3. Correct statement about constructor overloading in C# is?

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

 class maths
 {
     public maths()
     {
         Console.WriteLine("constructor 1 :");
     }
     public maths(int x)
     {
         int p = 2;
         int u;
         u = p + x;
         Console.WriteLine("constructor 2: " +u);
     }
 }
 class Program
 {
     static void Main(string[] args)
     {
         maths k = new maths(4);
         maths t = new maths();
         Console.ReadLine();
     }
 }

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

 class maths
 {
     int i;
     public maths(int ii)
     {
         ii = 12;
         int j = 12;
         int r = ii * j;
         Console.WriteLine(r);
     }
 }
 class maths1 : maths
 {
     public maths1(int u) :base(u)
     {
         u = 13;
         int h = 13;
         Console.WriteLine(u + h);
     }
 }
 class maths2 : maths1
 {
     public maths2(int k) :base(k)
     {
         k = 24;
         int o = 6 ;
         Console.WriteLine(k /o);
     }
 }
 class Program
 {
     static void Main(string[] args)
     {
         maths2 t = new maths2(10);
         Console.ReadLine();
     }
 }

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

 
 class maths
 {
     public int length;
     public int breadth;
     public maths(int x, int y)
     {
         length = x;
         breadth = y;
         Console.WriteLine(x + y);
     }
     public maths(double x, int y)
     {
         length = (int)x;
         breadth = y;
         Console.WriteLine(x * y);
     }
 }
class Program
{
    static void Main(string[] args)
    {
        maths m = new maths(20, 40);
        maths k = new maths(12.0, 12);
        Console.ReadLine();
    }
}

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

 class maths
 {
     public int length;
     public int breadth;
     public  maths(int x)
     {
         length = x + 1;
     }
     public maths(int x, int y)
     {
         length = x + 2;
     }
 }
 class Program
 {
     static void Main(string[] args)
     {
         maths m = new maths(6);
         maths k = new maths(6, 2);
         Console.WriteLine(m.length);
         Console.WriteLine(k.length);
         Console.ReadLine();
     }
 }

8. Which keyword is used to refer baseclass constructor to subclass constructor?

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

  class maths
  {
      static maths()
      {
          int s = 8;
          Console.WriteLine(s);
      }
      public  maths(int f)
      {
          int h = 10;
          Console.WriteLine(h);
      }
  }
  class Program
  {
      static void Main(string[] args)
      {
          maths p = new maths(0);
          Console.ReadLine();
      }
  }

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

class maths
{
    int i;
    public  maths(int ii)
    {
        ii = -25;
        int g;
        g = ii > 0 ? ii : ii * -1;
        Console.WriteLine(g);
    }
}
class maths1 :maths
{
    public  maths1(int ll) :base(ll)
    {
        ll = -1000;
        Console.WriteLine((ll > 0 ? ll : ll * -1));
    }
}
class Program
{
    static void Main(string[] args)
    {
        maths1 p = new maths1(6);
        Console.ReadLine();
    }
}

 

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.