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

4/12

Page

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

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i = 10;
    double d = 35.78;
    fun(i);
    fun(d);
    Console.ReadLine();
}
static void fun(double d)
{
    Console.WriteLine(d);
}

Select an option to see the answer and solution.

What will be the Correct statement in the following C# code?
class baseclass
{
    int a;
    public baseclass(int a1) 
    {
        a = a1;
        console.writeline(" a ");
    }
    class derivedclass : baseclass
    {
        public derivedclass (int a1) : base(a1)
        {
            console.writeline(" b ");
        }
    }
    class program
    {
        static void main(string[] args)
        {
            derivedclass d =  new derivedclass(20);
        }
    }
}

Select an option to see the answer and solution.

The process of defining a method in a subclass having same name & type signature as a method in its superclass is known as?

Select an option to see the answer and solution.

Wrong statement about enum used in C#.NET is?

Select an option to see the answer and solution.

What is the return type of destructor?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class A 
{
    public int i;
    protected int j;
}    
class B : A 
{
    public int j;
    public void display() 
    {
        base.j = 3;
        Console.WriteLine(i + " " + 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.

Access specifiers which can be used for an interface are?

Select an option to see the answer and solution.

A class consists of two interfaces with each interface consisting of three methods. The class had no instance data. Which of the following indicates the correct size of object created from this class?

Select an option to see the answer and solution.

Choose the correct statements among the following:

Select an option to see the answer and solution.

What will be the output of the following C# code?
class overload
{
    public int x;
    int y;
    public int add(int a)
    {
        x = a + 1;
        return x;
    }
    public int add(int a, int b)
    {
        x = a + 2;
        return x;
    }
}    
class Program
{
    static void Main(string[] args)
    {
        overload obj = new overload();
        overload obj1 = new overload();
        int a = 0;
        obj.add(6);
        obj1.add(6, 2);
        Console.WriteLine(obj.x);
        Console.WriteLine(obj1.x);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Which reference modifier is used to define reference variable?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class maths
{
    int i;
    public maths(int x)
    {
        i = x;
        Console.WriteLine(" hello: ");
    }
}
class maths1 : maths
{
    public  maths1(int x) :base(x)
    {
        Console.WriteLine("bye");
    }
}
class Program
{
    static void Main(string[] args)
    {
        maths1 k = new maths1(12);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

"A mechanism that binds together code and data in manipulates, and keeps both safe from outside interference and misuse. In short it isolates a particular code and data from all other codes and data. A well-defined interface controls access to that particular code and data."

Select an option to see the answer and solution.

To override a method in the subclass, the base class method should be defined as?

Select an option to see the answer and solution.

Calculate the number of bytes a structure variable s occupies in the memory if it is defined as follows.
class abc
{
    int i;
    Decimal d;
}
struct sample
{
   private int x;
   private Single y;
   private trial z;
}
sample s = new sample();

Select an option to see the answer and solution.

What is Recursion in CSharp defined as?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class maths
{
    int i;
    public maths(int ii)
    {
        ii = 12;
        int j = 12;
        int r = ii * j;
        Console.WriteLine(r);
    }
}
class maths1 : maths
{
    public maths1(int u) :base(u)
    {
        u = 13;
        int h = 13;
        Console.WriteLine(u + h);
    }
}
class maths2 : maths1
{
    public maths2(int k) :base(k)
    {
        k = 24;
        int o = 6 ;
        Console.WriteLine(k /o);
    }
}
class Program
{
    static void Main(string[] args)
    {
        maths2 t = new maths2(10);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Which keyword is used to refer baseclass constructor to subclass constructor?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class test
{
    public void print()
    {
        Console.WriteLine("Csharp:");
    }
}
class Program
{
    static void Main(string[] args)
    {
        test t;
        t.print();
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Which return statement correctly returns the output?

Select an option to see the answer and solution.