My Report

C# OOP 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. The correct way to define a variable of type struct abc in the following C# code?

 struct abc
 { 
     public string name;
     protected internal int age;
     private Single sal;
 }

2. Calculate the number of bytes a structure variable s occupies in the memory if it is defined as follows.

  class abc
  {
      int i;
      Decimal d;
  }
  struct sample
  {
     private int x;
     private Single y;
     private trial z;
  }
  sample s = new sample();

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

struct book
{
    private String name;
    private int pages;
    private Single price;
}
book b = new book();

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

 {
     struct abc
     {
         int i;
     }
     class Program
     {
         static void Main(string[] args)
         {
             abc x = new abc();
             abc z;
             x.i = 10;
             z = x;
             z.i = 15;
             console.Writeline(x.i + "  " + y.i)
         }
     }
 }

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

{
    struct abc
    {
        public int i;
    }  
    class Program
    {
        static void Main(string[] args)
        {
            sample a = new sample();
            a.i = 10;
            fun(ref a);
            Console.WriteLine(a.i);
        }
        public static voidn fun(ref sample x)
        {
            x.i = 20; 
            Console.WriteLine(x.i);
        }
    }
}

6. Choose the correct statement among the following which supports the fact that C# does not allow the creation of empty structures?

7. Which of the following is the correct way to settle down values into the structure variable 'e' defined in the following C# code snippet?

 struct emp
 { 
     public String name;
     public int age;
     public Single sal;
 }
 emp e = new emp();

8. When does a structure variable get destroyed?

9. Select the wrong statements among the following?

10. Which of the following is the correct result for the given statement in the C#.NET statement given below?
p = q

struct employee
{
    private int employee id;
    private string city;
}
employee q = new employee();
employee p;
p = q;

11. Choose the wrong statement about structures in C#.NET?

12. Choose the correct statement about structures as to why they are defined as value types but not reference types?

13. What will be the correct statement in the following C# code?

class trial
{
    int i;
    float d;
}
struct sample
{
    private int x;
    private Single y;
    private trial z;
}
sample s = new sample();

 

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.