Vidyalelo
C# Programming · all questions

Classes and Objects in C Sharp
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

238

Questions

8/12

Page

Pick an option on a question to see the right answer and solution.

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?

Select an option to see the answer and solution.

Which method has the same name as that of its class?

Select an option to see the answer and solution.

Wrong statement about run time polymorphism is?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class recursion 
{
    int fact(int n) 
    {
        int result;
        if (n == 1)
        return 1;
        result = fact(n - 1) * n;
        return result;
    }
} 
class Program 
{
    public static void main(String args[]) 
    {
        recursion obj = new recursion() ;
        Console.WriteLine(obj.fact(4));
    }
}

Select an option to see the answer and solution.

Which of the following statements are correct?

Select an option to see the answer and solution.

Correct statement about constructors in C#.NET is?

Select an option to see the answer and solution.

Which of the following modifiers is used when an abstract method is redefined by a derived class?

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int[] arr = new int[] {1, 2, 3, 4, 5};
    fun1(ref arr);
    Console.ReadLine();
 }
static void fun1(ref int[] array)
{
    for (int i = 0; i < array.Length; i++)
    {
        array[i] = array[i] + 5;
        Console.WriteLine(array[i] + " ");
    }
}

Select an option to see the answer and solution.

Choose the correct statement among the below mentioned statements.

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
   int a = 5;
   fun1 (ref a);
   Console.WriteLine(a);
   Console.ReadLine();
}
static void fun1(ref int a)
{
    a = a * a;
}

Select an option to see the answer and solution.

Correct way to define object of sample class in which C# code will work correctly is:
class abc
{
    int i;
    float k;
    public abc(int ii, float kk)
    {  
        i = ii;
        k = kk;
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
class maths
{
    public int fun(int k, int y)
    {
        return k + y;
    }
    public int fun1(int t, float z)
    {
        return (t+(int)z);
    }
}    
class Program
{
    static void Main(string[] args)
    {
        maths obj = new maths();
        int i;
        int b = 90;
        int c = 100;
        int d = 12;
        float l = 14.78f;
        i = obj.fun(b, c);
        Console.WriteLine(i);
        int j = (obj.fun1(d,  l));
        Console.WriteLine(j);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Select the correct statement from the following?

Select an option to see the answer and solution.

The method called by clients of a class to explicitly release any resources like network, connection, open files etc. When the object is no longer required?

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i = 5;
    int j  = 6;
    add(ref i);
    add(6);
    Console.WriteLine(i);
    Console.ReadLine();
}
static void add(ref int x)
{
    x = x * x;
}
static void add(int x)
{
    Console.WriteLine(x * x * x);
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
class sample
{
    public int i;
    public int j;
    public void fun(int i, int j)
    {
        this.i = i;
        this.j = j;
    }
}
class Program
{
    static void Main(string[] args)
    {
        sample s = new sample();
        s.i = 1;
        s.j = 2;
        s.fun(s.i, s.j);
        Console.WriteLine(s.i + " " + s.j);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What will be size of the object created depicted by C# code snippet?
class baseclass
{
    private int a;
    protected int b;
    public int c;
}
class derived : baseclass
{
    private int x;
    protected int y;
    public int z;
}
class Program
{
    static Void Main(string[] args)
    {
        derived a = new derived();
    }
}

Select an option to see the answer and solution.

Correct way to define operator method or to perform operator overloading is?

Select an option to see the answer and solution.

When a function fun() is to receive an int, a single & a double and it is to return a decimal, then the correct way of defining this C# function is?

Options are not available for this question.

Select an option to see the answer and solution.

Which of the following statements is correct about constructors in C#.NET?

Select an option to see the answer and solution.