My Report

C# Programming Mock Test 5


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

Question 1 of 10

1. Which statements are correct about operator overloading?

Question 1 of 10

Question 2 of 10

2. 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();
     }
 }

Question 2 of 10

Question 3 of 10

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

 class maths
 {
     public int fun(int ii)
     {
         return(ii > 0 ? ii :ii * -1);
     }
     public long fun(long ll)
     {
         return(ll > 0 ? ll :ll * -1);
     }
     public double fun( double dd)
     {
         return(dd > 0 ? dd :dd * -1);
     }
 }    
 class Program
 {
     static void Main(string[] args)
     {
         maths obj = new maths();
         int i = -25;
         int j ;
         long l = -100000l ;
         long m;
         double d = -12.34;
         double e;
         j = obj.fun(i);
         m = obj.fun(l);
         e = obj.fun(d);
         Console.WriteLine(j + "  " + m + "  " + e);
         Console.ReadLine();
     }
 }

Question 3 of 10

Question 4 of 10

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

 
 class maths
 {
     public static void fun1()
     {
         Console.WriteLine("method 1 :");
     }
     public void fun2()
     {
         fun1();
         Console.WriteLine("method 2 :");
     }
     public void fun2(int k)
     {
         Console.WriteLine(k);
         fun2();
     }
 }    
 class Program
 {
     static void Main(string[] args)
     {
         maths obj = new maths();
         maths.fun1();
         obj.fun2(20);
         Console.ReadLine();
     }
 }

Question 4 of 10

Question 5 of 10

5. 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();
    }
}

Question 5 of 10

Question 6 of 10

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

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

Question 6 of 10

Question 7 of 10

7. The modifier used to define a class which does not have objects of its own but acts as a base class for its subclass is?

Question 7 of 10

Question 8 of 10

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

 
 class A 
 {
     public virtual void display() 
     {
         Console.WriteLine("A");
     }    
 }    
 class B: A 
 {
    public override void display() 
    {
        Console.WriteLine(" B ");
    } 
 }    
class Program
{
    static void Main(string[] args)
    {
        A obj1 = new A();
        B obj2 = new B();
        A r;
        r = obj1;
        r.display();
        r = obj2;
        r.display();     
        Console.ReadLine();
    }
}

Question 8 of 10

Question 9 of 10

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

Question 9 of 10

Question 10 of 10

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

 class baseclass
 {
     int a;
     public baseclass(int a1) 
     {
         a = a1;
         console.writeline(" a ");
     }
     class derivedclass : baseclass
     {
         public derivedclass (int a1) : base(a1)
         {
             console.writeline(" b ");
         }
     }
     class program
     {
         static void main(string[] args)
         {
             derivedclass d =  new derivedclass(20);
         }
     }
 }

Question 10 of 10


 

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.