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

11/12

Page

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

If a class inheriting an abstract class does not define all of its functions then it is known as?

Select an option to see the answer and solution.

What will be the output of the following C# code?
namespace ConsoleApplication4
{
    class A
    {
        public int i;
        public void display()
        {
            Console.WriteLine(i);
        }
    }    
    class B: A 
    {
        public int j;
        public void display() 
        {
            Console.WriteLine(j);
        }
    }    
    class Program
    {
        static void Main(string[] args)
        {
            B obj = new B();
            obj.j = 1;
            obj.i = 8;
            obj.display();
            Console.ReadLine();
        }
    }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following C# code?
class sample
{
    public sample()
    {
        Console.WriteLine("THIS IS BASE CLASS constructor");
    }
 }    
public class sample1 : sample 
{
 
}    
class Program
{
    static void Main(string[] args)
    {
        sample1 obj = new sample1();
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Select the wrong statements among the following?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class maths
{
    public int x;
    public double y;
    public int add(int a, int b)
    {
        x = a + b;
        return x;
    }
    public int add(double c, double d)
    {
        y = c + d;
        return (int)y;
    }
    public maths()
    {
        this.x = 0;
        this.y = 0;
    }
}    
class Program
{
    static void Main(string[] args)
    {
        maths obj = new maths();
        int a = 4;
        double b = 3.5;
        obj.add(a, a);
        obj.add(b, b);
        Console.WriteLine(obj.x + " " + obj.y);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What will be the Correct statement in the following C# code?
interface a1
{
    void f1();
    int f2();
}
class a :a1
{
    void f1()
    {
    }
    int a1.f2()
    {
    }
}

Select an option to see the answer and solution.

Which of the following statements are correct in nature?

Select an option to see the answer and solution.

Which form of inheritance is not supported directly by C# .NET?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which among the following differentiates enum in C#.NET from enum in C language?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class a
{
    public  void fun()
    {
        Console.WriteLine("base method");
    }
}
class b: a
{
    public new void fun()
    {
        Console.WriteLine(" derived method ");
    }
}
class Program
{
    static void Main(string[] args)
    {
        b k = new b();
        k.fun();
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
class sample
{
    public  int i;
    void display() 
    {
        Console.WriteLine(i);
    }
}    
class sample1 : sample 
{
    public  int j;
    public void display() 
    {
        Console.WriteLine(j);
    }
}    
class Program
{
    static void Main(string[] args)
    {
        sample1 obj = new sample1();
        obj.i = 1;
        obj.j = 2;
        obj.display();
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
 class abc
 {
     public static void a()
     {
         console.writeline("first method");
     }
     public void b()
     {
         a();
         console.writeline("second method");
     }
     public void b(int i)
     {
         console.writeline(i);
         b();
     }
 }
 class program
 {
     static void main()
     {
         abc k = new abc();
         abc.a();
         k.b(20);
     }
 }

Select an option to see the answer and solution.

What will be the output of the following C# code?
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine( vol(10));
        Console.WriteLine( vol(2.5f,  5));
        Console.WriteLine( vol( 5l,  4,  5));
        Console.ReadLine();
    }
    static int vol(int x)
    {
        return(x * x * x);
    }
    static float vol(float r,  int h)
    {
        return(3.14f * r * r * h);
    }
    static long vol(long l, int b, int h)
    {
        return(l * b * h);
    }
}

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, int n)
    {
        Console.WriteLine(k + "  " + y + "  " + n);
        return (k);
    }
    public int fun1(int t,float z)
    {
        Console.WriteLine(t + "  " + z);
        return t;
    }
}    
class Program
{
    static void Main(string[] args)
    {
        maths obj = new maths();
        int b = 90;
        int c = 100;
        int d ;
        float l;
        int i = obj.fun(b, c, 12);
        int j = (obj.fun1(12, 14.78f));
        Console.ReadLine();
    }
}

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[] arr = new int[10];
    public void fun(int i, int val)
    {
        arr[i] = val;
    }
}
class Program
{
    static void Main(string[] args)
    {
        sample s = new sample();
        s.i = 10;
        sample.fun(1, 5);
        s.fun(1, 5);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of the following statements are correct about functions?

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 X = 0;
    if (Convert.ToBoolean(X = 0))
    Console.WriteLine("It is zero");
    else 
    Console.WriteLine("It is not zero");
    Console.ReadLine();
}

Select an option to see the answer and solution.