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

6/12

Page

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

What will be the output of the following C# expression?
int a+= (float) b/= (long)c.

Select an option to see the answer and solution.

Which of the following statements is correct?

Select an option to see the answer and solution.

Which statements are correct?

Select an option to see the answer and solution.

How many values does a function return?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What does the following C# code imply?
csharp abc;
abc = new charp();

Select an option to see the answer and solution.

Choose the correct statements 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?
 class A 
 {
     public virtual void display() 
     {
         Console.WriteLine("A");
     }    
 }    
 class B: A 
 {
    public override void display() 
    {
        Console.WriteLine(" B ");
    } 
 }    
class Program
{
    static void Main(string[] args)
    {
        A obj1 = new A();
        B obj2 = new B();
        A r;
        r = obj1;
        r.display();
        r = obj2;
        r.display();     
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Which is the correct way to create an object of the given class abc?

Select an option to see the answer and solution.

Which of these is not a correct statement?

Select an option to see the answer and solution.

Name a method which has the same name as that of class and which is used to destroy objects also called automatically when application is finally on process of being getting terminated.

Select an option to see the answer and solution.

Which statements are correct about operator overloading?

Select an option to see the answer and solution.

Choose the wrong statement from the given set of statements?

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);
}
public  class maths :calc 
{
    public int x;
    public void cal(int i) 
    {
        x = i * i;            
    }
}
class Program
{
    public static void Main(string[] args)
    {            
        display arr = new display();
        arr.x = 0;      
        arr.cal(2);
        Console.WriteLine(arr.x);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
enum color:int
{
    red,
    green,
    blue = 5,
    cyan,
    pink = 10,
    brown
}
console.writeline((int)color.green);
console.writeline((int)color.brown);

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 = -25;
        int g;
        g = ii > 0 ? ii : ii * -1;
        Console.WriteLine(g);
    }
}
class maths1 :maths
{
    public  maths1(int ll) :base(ll)
    {
        ll = -1000;
        Console.WriteLine((ll > 0 ? ll : ll * -1));
    }
}
class Program
{
    static void Main(string[] args)
    {
        maths1 p = new maths1(6);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Operators that can be overloaded are?

Select an option to see the answer and solution.

Which of the following cannot be used to declare a class as a virtual?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class maths
{
    public static void fun1()
    {
        Console.WriteLine("method 1 :");
    }
    public void fun2()
    {
        fun1();
        Console.WriteLine("method 2 :");
    }
    public void fun2(int k)
    {
        Console.WriteLine(k);
        fun2();
    }
}    
class Program
{
    static void Main(string[] args)
    {
        maths obj = new maths();
        maths.fun1();
        obj.fun2(20);
        Console.ReadLine();
    }
}

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 = 10 , b = 20;
    Console.WriteLine("Result before swap is: "+ a +" "+b);
    swap(ref a, ref b);
    Console.ReadLine();
}
static void swap(ref int i, ref int j)
{
    int t;
    t = i;
    i = j;
    j = t;
    Console.WriteLine("Result after swap is:"+ i +" "+j);
}

Select an option to see the answer and solution.