Sail E0 Webinar

MCQs

Total Questions : 13 | Page 1 of 2 pages
Question 1. The correct way to define a variable of type struct abc among the following is?
struct abc {      public string name;     protected internal int age;     private Single sal; }
  1.    abc e = new abc();
  2.    abc();
  3.    abc e; e = new abc;
  4.    abc e = new abc;
 Discuss Question
Answer: Option A. -> abc e = new abc();




Question 2. 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 ();     } }
  1.    f1() of derived class get executed f2() of derived class get executed f3() of base class get executed
  2.    f1() of base class get executed f2() of derived class get executed f3() of base class get executed
  3.    f1() of base class get executed f2() of derived class get executed f3() of derived class get executed
  4.    f1() of derived class get executed f2() of base class get executed f3() of base class get executed
 Discuss Question
Answer: Option B. -> f1() of base class get executed f2() of derived class get executed f3() of base class get executed




Question 3. What will be the correct output for the given code snippet?
class maths  {     int fact(int n)      {         int result;         if (n == 1)         return 1;         result = fact(n - 1) * n;         return result;     } }  class Output  {     static void main(String args[])      {         maths obj = new maths() ;         Console.WriteLine(obj.fact(4)*obj.fact(2));     } }
  1.    64
  2.    60
  3.    120
  4.    48
 Discuss Question
Answer: Option D. -> 48


4! = 4*3*2*1 & 2! = 2*1 .So, 24*2 = 48.
Output : 48


Question 4. What will be the output of the given code snippet?
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();     } }
  1.    0 0
  2.    2 2
  3.    4 1
  4.    1 4
 Discuss Question
Answer: Option C. -> 4 1


class displayA executes the interface calculate by doubling the value of item . Similarly class displayB implements the interface by dividing item by item.So, variable x of class displayA stores 4 and variable x of class displayB stores 1.
Output : 4, 1


Question 5. What will be the output for the given set of 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();     } }
  1.    0
  2.    2
  3.    1
  4.    Compile time error
 Discuss Question
Answer: Option B. -> 2


When method display() is called using objects of class 'B'. The method 'display()' for class 'B' is called instead of class 'A' as class 'B' is inherited by class 'A'.
Output :2


Question 6. What would be output for the set of code?
class maths {     public int x;     public double y;     public int add(int a, int b)     {         x = a + b;         return x;     }     public int add(double c, double d)     {         y = c + d;         return (int)y;     }     public maths()     {         this.x = 0;         this.y = 0;     } }    class Program{    static void Main(string[] args)    {        maths obj = new maths();        int a = 4;        double b = 3.5;        obj.add(a, a);        obj.add(b, b);        Console.WriteLine(obj.x + " " + obj.y);        Console.ReadLine();    }}
  1.    4, 3.5
  2.    8, 0
  3.    7.5, 8
  4.    8, 7
 Discuss Question
Answer: Option D. -> 8, 7




Question 7. Correct way to define operator method or to perform operator overloading is?
  1.    public static op(arglist) { }
  2.    public static retval op(arglist) { }
  3.    public static retval operator op(arglist) { }
  4.    All of the mentioned
 Discuss Question
Answer: Option C. -> public static retval operator op(arglist) { }




Question 8. Which keyword is used for correct implementation of an interface in C#.NET?
  1.    interface
  2.    Interface
  3.    intf
  4.    Intf
 Discuss Question
Answer: Option A. -> interface




Question 9. What will be the output for the given set of 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();        }    }}
  1.    2, 10 12
  2.    0, 10 10
  3.    2, 0 2
  4.    0, 0 0
 Discuss Question
Answer: Option C. -> 2, 0 2


Abstract method implementation is processed in subclass 'B' .Also the object 'obj' of abstract class 'A' initializes value of i as 2.The object of class 'B' also initializes value of j as 10.Since, the method display() is called using object of class A which is 'obj' and hence i = 2 whereas j = 0 .So, sum = 2.
Output : 2 0
sum is : 2


Question 10. Which keyword is used to refer baseclass constructor to subclass constructor?
  1.    This
  2.    static
  3.    base
  4.    extend
 Discuss Question
Answer: Option C. -> base




Latest Videos

Latest Test Papers