My Report

C# OOP Test – 1


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?

 public class sample
 {
     public static int x = 100;
     public static int y = 150;
    
 }
 public class newspaper :sample
 {
     new public static int x = 1000;
     static void Main(string[] args)
     {
         console.writeline(sample.x + "  " + sample.y + "  " + x);
     }
 }

2. Select the sequence of execution of function f1(), f2() & f3() in C# .NET CODE?

 class base
 {
     public void f1() {}
     public virtual void f2() {}
     public virtual  void f3() {}
 }
 class derived :base
 {
     new public void f1() {}
     public override void f2() {}
     public new void f3() {}
 } 
 class Program
 {
     static void Main(string[] args)
     {
         baseclass b = new derived();
         b.f1 ();
         b.f2 ();
         b.f3 ();
     }
 }

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

 public class maths
 {
     public int x;
     public virtual void a()
     {

     }
  
 }
 public class subject : maths
 {
     new public void a()
     {

     }

 }

4. Correct way to overload +operator?

5. Which of the following statements is correct?

6. Selecting appropriate method out of number of overloaded methods by matching arguments in terms of number, type and order and binding that selected method to object at compile time is called?

7. Correct code to be added for overloaded operator - for the following C# code?

 class csharp
 {
     int x, y, z;
     public csharp()
     {

     }
     public csharp(int a ,int b ,int c)
     {
         x = a;
         y = b;
         z = c;
     }
     Add correct set of code here
    public void display()
    {
        console.writeline(x + "  " + y + "  " + z);
    }
    class program
    {
        static void Main(String[] args)
        {
            csharp s1 = new csharp(5 ,6 ,8);
            csharp s3 = new csharp();
            s3 = - s1;
            s3.display();
        }
    }
}

8. Wrong statement about run time polymorphism is?

9. The capability of an object in Csharp to take number of different forms and hence display behaviour as according is known as ___________

10. Which of the following keyword is used to change data and behavior of a base class by replacing a member of the base class with a new derived member?


 

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.