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

5/12

Page

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

Which statements among following are correct?

Select an option to see the answer and solution.

Which of these can be used to fully abstract a class from its implementation?

Select an option to see the answer and solution.

Select the class visibility modifiers among the following:

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following C# code?
class maths
{
    static maths()
    {
        int s = 8;
        Console.WriteLine(s);
    }
    public  maths(int f)
    {
        int h = 10;
        Console.WriteLine(h);
    }
}
class Program
{
    static void Main(string[] args)
    {
        maths p = new maths(0);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
enum days:int
{
    sunday = -3,
    monday,
    tuesday
}
Console.WriteLine((int)days.sunday);
Console.WriteLine((int)days.monday);
Console.WriteLine((int)days.tuesday);

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 = 6,Y = 2;
   X  *= X / Y;
   Console.WriteLine(X);
   Console.ReadLine();
}

Select an option to see the answer and solution.

Which of the following is the correct way of implementing an interface addition by class maths?

Select an option to see the answer and solution.

What does the following C# code signify?
class a
{
 
 
 
}
class b : a
{
    variable declaration;
    method declaration;
}

Select an option to see the answer and solution.

What will be the Correct statement in the following C# code?
interface abc
{
    String FirstName
    {
        get;
        set;
    }
   String LastName
   {
       get;
       set;
   }
   void print();
   void stock();
   int fun();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
interface i1
{
    void f1();
}
interface i2 :i1
{
    void f2();
}
public class maths :i2
{
    public void f2()
    {
        Console.WriteLine("fun2");
    }
    public void f1()
    {
        Console.WriteLine("fun1");
    }
}
class Program
{
    static Void Main()
    {
        maths m = new maths();
        m.f1();
        m.f2();
    }
}

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 abstract void display();
    }    
    class B: A 
    {
        public  int j;
        public int sum;
        public override void display() 
        {
            sum = i + j;
            Console.WriteLine(+i + "\n" + +j);
            Console.WriteLine("sum is:" +sum);
        }
    }    
    class Program
    {
        static void Main(string[] args)
        {
            A obj = new B();
            obj.i = 2;
            B obj1 = new B();
            obj1.j = 10;
            obj.display();
            Console.ReadLine();
        }
    }
}

Select an option to see the answer and solution.

The process of defining two or more methods within the same class that have same name but different parameters list?

Select an option to see the 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, int y)
     {
         length = x;
         breadth = y;
         Console.WriteLine(x + y);
     }
     public maths(double x, int y)
     {
         length = (int)x;
         breadth = y;
         Console.WriteLine(x * y);
     }
 }
class Program
{
    static void Main(string[] args)
    {
        maths m = new maths(20, 40);
        maths k = new maths(12.0, 12);
        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 x = 4 ,b = 2;
    x -= b/= x * b;
    Console.WriteLine(x + " " + b);
    Console.ReadLine();
}

Select an option to see the answer and solution.

Which of these keywords is used to refer to member of base class from a sub class?

Select an option to see the answer and solution.

Which of the following functionality is facilitated by inheritance mechanism?

Select an option to see the answer and solution.

What is the process of defining a method in terms of itself, that is a method that calls itself?

Select an option to see the answer and solution.

Which keyword is used to declare a base class method while performing overriding of base class methods?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class z
{
    public string name1;
    public string address;
    public void show()
    {
        Console.WriteLine("{0} is in city{1}", name1, " ", address);
    }
}
class Program
{
    static void Main(string[] args)
    {
        z n = new z();
        n.name1 = "harsh";
        n.address = "new delhi";
        n.show();
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.