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

9/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?
class maths
{
    public int length;
    public int breadth;
    public  maths(int x)
    {
        length = x + 1;
    }
    public maths(int x, int y)
    {
        length = x + 2;
    }
}
class Program
{
    static void Main(string[] args)
    {
        maths m = new maths(6);
        maths k = new maths(6, 2);
        Console.WriteLine(m.length);
        Console.WriteLine(k.length);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Which of the following cannot be used to declare an interface correctly?

Select an option to see the answer and solution.

In an inheritance chain through which of the following, the base class and its components are accessible to the derived class?

Select an option to see the answer and solution.

What will be the output of the following C# code?
public class sample
{
    public static int x = 100;
    public static int y = 150;

}
public class newspaper :sample
{
    new public static int x = 1000;
    static void Main(string[] args)
    {
        console.writeline(sample.x + "  " + sample.y + "  " + x);
    }
}

Select an option to see the answer and solution.

Which of the following is used to define the member of a class externally?

Select an option to see the answer and solution.

Which of these can be overloaded?

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)
    {
        width = w;
        height = h;
        length = l;
    }
   public ~box()
   {
       volume = width * length * height;

   }

}    
class Program
{
    static void Main(string[] args)
    {
       box b = new box(4, 5, 9);
       Console.WriteLine(b.volume);
       Console.ReadLine();
   }
 
}

Select an option to see the answer and solution.

Operator used to free the memory when memory is allocated?

Select an option to see the answer and solution.

Choose the statements which makes interface different from classes?

Select an option to see the answer and solution.

What will be the output of the following C# code?
using System;
public class BaseClass
{
    public BaseClass()
    {
        Console.WriteLine("I am a base class");
    }
}
public class ChildClass : BaseClass
{
    public ChildClass()
    {
        Console.WriteLine ("I am a child class");
    }
static void Main()
{
    ChildClass CC = new ChildClass();
}
}

Select an option to see the answer and solution.

What will be the Correct statement in the following C# code?
class sample
{
    protected int index;
    public sample()
    {
        index = 0;
    }
}
class sample 1: sample
{
    public void add()
    {
        index += 1;
    }
}
class Program
{
    static void Main(string[] args)
    {
        sample 1 z = new sample 1();
        z . add();
    }
}

Select an option to see the answer and solution.

Choose the correct statement about structures as to why they are defined as value types but not reference types?

Select an option to see the answer and solution.

What will be the output of the following C# code?
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.i = 1;
        obj.j = 2;
        obj.display();
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Does C#.NET support partial implementation of interfaces?

Select an option to see the answer and solution.

Which statement correctly defines Interfaces in C#.NET?

Select an option to see the answer and solution.

What will be the correct statement in the following C# code?
class trial
{
    int i;
    float 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 will be the output of the following C# code?
namespace ConsoleApplication4
{
    abstract class A
    {
        public int i ;
        public int j ;
        public abstract void display();
    }    
    class B: A    
    {
        public int j = 5;
        public override void display() 
        {
            this.j = 3;
            Console.WriteLine(i + "  " + j);
        }
    }    
    class Program
    {
        static void Main(string[] args)
        {
            B obj = new B();
            obj.i = 1;
            obj.display();     
            Console.ReadLine();
        }
    }
}

Select an option to see the answer and solution.

What will be the correct statement in the following C# code?
struct book
{
    private String name;
    private int pages;
    private Single price;
}
book b = new book();

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 = 8;
    int b = 16;
    int C = 64;
    x /= b /= C;
    Console.WriteLine(x + " " + b+ " " +C);
    Console.ReadLine();
}

Select an option to see the answer and solution.

Which procedure among the following should be used to implement a 'Has a' or a 'Kind of' relationship between two entities?

Select an option to see the answer and solution.