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

12/12

Page

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

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;

Select an option to see the answer and solution.

The operator used to access member function of a class?

Select an option to see the answer and solution.

Select the statement which should be added to the current C# code to get the output as 10 20?
class baseclass
{
    protected int a = 20;
}
class derived : baseclass
{
    int a = 10;
    public void math()
    {
         /* add code here */
    }   
}

Select an option to see the answer and solution.

Which among the following cannot be used as a datatype for an enum in C#.NET?

Select an option to see the answer and solution.

Which of the following statements about objects in "C#" is correct?

Select an option to see the answer and solution.

Which of these data types is used by the operating system to manage the Recursion in Csharp?

Select an option to see the answer and solution.

What will be the output of the following C# code?
interface calc
{
    void cal(int i);
}
class displayA :calc 
{
    public int x;
    public void cal(int i) 
    {
        x = i * i;            
    }
}
class displayB :calc
{
    public int x;
    public void cal(int i)
    {
        x = i / i;
    }
}
class Program
{
    public static void Main(string[] args)
    {            
        displayA arr1 = new displayA();
        displayB arr2 = new displayB();
        arr1.x = 0;
        arr2.x = 0;
        arr1.cal(2);
        arr2.cal(2);
        Console.WriteLine(arr1.x + " " + arr2.x);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Select correct differences between '=' and '==' in C#.

Select an option to see the answer and solution.

The modifier used to hide the base class methods is?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class box
{
    public int volume;
    int width;
    int height;
    int length;
    public box ( int w, int h, int l)
    {
        this.width = w;
        this.height = h;
        this.length = l;
    }
    ~ box()
    {
        volume = this.width * this.length * this.height;
        console.writeline(volume);
    }
}    
class Program
{
    public  static void Main(string[] args)
    {
        box b = new box(4, 5, 9);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Wrong statement about inheritance in C# .NET?

Select an option to see the answer and solution.

Correct way of declaration of object of the following class is?
class name

Select an option to see the answer and solution.

Select the sequence of execution of function f1(), f2() & f3() in C# .NET CODE?
class base
{
    public void f1() {}
    public virtual void f2() {}
    public virtual  void f3() {}
}
class derived :base
{
    new public void f1() {}
    public override void f2() {}
    public new void f3() {}
} 
class Program
{
    static void Main(string[] args)
    {
        baseclass b = new derived();
        b.f1 ();
        b.f2 ();
        b.f3 ();
    }
}

Select an option to see the answer and solution.

The following C# code is run on single level of inheritance. What will be the Correct statement in the following C# code?
class sample
{
    int i = 10;
    int j = 20;
    public void display() 
    {
        Console.WriteLine("base method ");
    }
}    
class sample1 : sample 
{
    public  int s = 30;
}    
class Program
{
    static void Main(string[] args)
    {
        sample1 obj = new sample1();
        Console.WriteLine("{0}, {1}, {2}", obj.i,  obj.j,  obj.s);
        obj.display();
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What is the return type of constructors?

Select an option to see the answer and solution.

Which keyword is used for correct implementation of an interface in C#.NET?

Select an option to see the answer and solution.

What will be the output of the following C# code?
public static void Main(string[] args)
{
    p();
    void p()
    {
        Console.WriteLine("hi");
    }
}

Select an option to see the answer and solution.

Can the method add() be overloaded in the following ways in C#?
public int add()  {    }
public float add(){    }

Select an option to see the answer and solution.