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

7/12

Page

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

Which of these will happen if the recursive method does not have a base case?

Select an option to see the answer and solution.

Which operator among the following signifies the destructor operator?

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 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    func(ref a);
    Console.ReadLine();
}
static void func(ref int[] x)
{
    Console.WriteLine(" numbers are:");
    for (int i = 0; i < x.Length; i++)
    {
        if (x[i] % 2 == 0)
        {
            x[i] = x[i] + 1;
            Console.WriteLine(x[i]);
        }
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
enum letters
{
    a,
    b,
    c
} 
letters l;
l = letters.a;
Console.writeline(l);

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 y = 3;
    y++;
    if (y <= 5)
    { 
        Console.WriteLine("hi");
        Main(args);
    }
    Console.ReadLine();
}

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

Select an option to see the answer and solution.

In Inheritance concept, which of the following members of base class are accessible to derived class members?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

A type of class which does not have its own objects but acts as a base class for its subclass is known as?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class maths
{
    public int fun1(int k)
    {
        k = 20;
        return k;
    }
    public Single fun1(float t)
    {
        t = 3.4f;
        return t;
    }
}  
class Program
{
    static void Main(string[] args)
    {
        maths obj = new maths();
        int i;
        i = obj.fun1(30);
        Console.WriteLine(i);
        Single j;
        j = obj.fun1(2.5f);
        Console.WriteLine(j);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What is the vector in operator overloading?

Select an option to see the answer and solution.

The number of levels of inheritance are?

Select an option to see the answer and solution.

A class member declared protected becomes member of subclass of which type?

Select an option to see the answer and solution.

Select the wrong statement about 'ref' keyword in C#?

Select an option to see the answer and solution.

Which of these operators must be used to inherit a class?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class sample
{
    int i;
    double k;
    public sample (int ii, double kk)
    {
        i = ii;
        k = kk;
        double j = (i) + (k);
        Console.WriteLine(j);
    }
    ~sample()
    {
        double j = i - k;
        Console.WriteLine(j);
    }
}
  class Program
  {
      static void Main(string[] args)
      {
          sample s = new sample(8, 2.5);
          Console.ReadLine();
      }
  }

Select an option to see the answer and solution.

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?

Select an option to see the answer and solution.

Correct statement about constructor overloading in C# is?

Select an option to see the answer and solution.

Select the correct statement among the given statements?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.