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

3/12

Page

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

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

Select an option to see the answer and solution.

Which of the following keyword is used to overload user defined types by defining static member functions?

Select an option to see the answer and solution.

If base class consist of two private integers, one static integer and derived class consist of two static integers and one private integer. What would be the size of derived class object?

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
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)*obj.fact(2));
     }
 }

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    Mul();
    m();
    Console.ReadLine();
}
static void Mul()
{
    Console.WriteLine("4");
}
static void m()
{
    Console.WriteLine("3");
    Mul();
}

Select an option to see the answer and solution.

Which among the following is the correct statement: Constructors are used to?

Select an option to see the answer and solution.

What will be the correct statement of the following C# code?
enum color:byte
{
    yellow = 500,
    green = 1000,
    pink = 1300
}

Select an option to see the answer and solution.

Choose the correct statement about enum used in C#.NET?

Select an option to see the answer and solution.

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

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

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

Select an option to see the answer and solution.

Which of the given modifiers can be used to prevent Method overriding?

Select an option to see the answer and solution.

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?

Select an option to see the answer and solution.

Choose the wrong statement about 'INTERFACE' in C#.NET?

Select an option to see the answer and solution.

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?

Select an option to see the answer and solution.

If no access modifier for a class is specified, then class accessibility is defined as?

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;
    int s = 0, c = 0;
    Mul (a, ref s, ref c);
    Console.WriteLine(s + "t " +c);
    Console.ReadLine();
}
static void Mul (int x, ref int ss, ref int cc)
{
    ss = x * x;
    cc = x * x * x;
}

Select an option to see the answer and solution.

Number of constructors a class can define is?

Select an option to see the answer and solution.

Correct way to overload +operator?

Select an option to see the answer and solution.

The data members of a class by default are?

Select an option to see the answer and solution.