Skip to main content

C#-Problamatic interview Questions

  


Q-1. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE SNIPPET?

using System;
public class emp
{
     public static int age = 40;
     public static int salary = 25000;

}
public class record :emp
{
     new public static int salary = 50000;
     static void Main(string[] args)
     {
         Console.WriteLine(emp.age + "  " + emp.salary + "  " + salary);
     }
}

a) 40, 25000, 50000
b) 40, 25000, 25000
c) 40, 50000, 50000
d) Error

Check correct option.
Answer. a)

Q-2. WHICH OF THE FOLLOWING KEYWORD, ENABLES TO MODIFY THE DATA AND BEHAVIOR OF A BASE CLASS BY REPLACING ITS MEMBER WITH A NEW DERIVED MEMBER?


a) overloads
b) overrides
c) new
d) base

Check correct option.
Answer. c)




Q-3. WHICH OF THE FOLLOWING IS THE CORRECT WAY TO OVERLOAD “+” OPERATOR?

a) public sample operator + ( sample a, sample b)
b) public abstract operator + (sample a, sample b)
c) public static sample operator + (sample a, sample b)
d) All of above

Check correct option.
Answer. d)

Q-4. WHAT WILL BE THE CORRECT ORDER OF EXECUTION OF FUNCTION FUNC1(), FUNC2() & FUNC3() IN THE GIVEN CODE SNIPPET?

class baseclass
{
     public void func1() {}
     public virtual void func2() {}
     public virtual  void func3() {}
}
class derivedclass :baseclass
{
     new public void func1() {}
     public override void func2() {}
     public new void func3() {}
}
class Program
{
     static void Main(string[] args)
     {
         baseclass b = new derivedclass();
         b.func1 ();
         b.func2 ();
         b.func3 ();
     }
}

a) func1() of derived class get executed
    func2() of derived class get executed
    func3() of base class get executed
b) func1() of base class get executed
    func2() of derived class get executed
    func3() of derived class get executed
c) func1() of derived class get executed
    func2() of base class get executed
    func3() of base class get executed
d) func1() of base class get executed
    func2() of derived class get executed
    func3() of base class get executed

Check correct option.
Answer. d)

Q-5. WHICH OF THE FOLLOWING STATEMENTS ARE CORRECT FOR C# LANGUAGE?

a) Every derived class does not define its own version of the virtual method.
b) By default, the access mode for all methods in C# is virtual.
c) If a derived class, does not define its own version of the virtual method, then the one present in the base class gets used.
d) All of the above.

Check correct option.
Answer. b)

Q-6. WHICH OF THE FOLLOWING CODE NEEDS TO BE ADDED FOR THE OVERLOADED OPERATOR “-” IN C#?

class example
{
int x, y, z;
public example()
{
}
public example(int a ,int b ,int c)
{
x = a;
y = b;
z = c;
}
//Add correct set of code here
public void display()
{
Console.WriteLine(x + "  " + y + "  " + z);
}
class program
{
static void Main(String[] args)
{
example obj1 = new example(5 ,6 ,8);
example obj2 = new example();
obj2 = - obj1;
obj2.display();
}
}
}

a)
public static example operator -(example obj1)
{
example t = new example();
t.x = obj1.x;
t.y = obj1.y;
t.z = -obj1.z;
return t;
}

b)


public static example operator -(example obj1)
{
  example t = new example();
  t.x = obj1.x;
  t.y = obj1.y;
  t.z = obj1.z;
  return t;
}
c)

public static example operator -(example obj1)
{
  example t = new example();
  t.x = -obj1.x;
  t.y = -obj1.y;
  t.z = -obj1.z;
  return t;
}
d) None of the above

Ans: C


Q-7. WHICH OF THE FOLLOWING IS THE CORRECT NAME FOR SELECTING AN APPROPRIATE METHOD FROM A NUMBER OF OVERLOADED METHODS, BY MATCHING THE ARGUMENTS IN TERMS OF THEIR NUMBER, TYPE, ORDER, AND BINDING AT COMPILE TIME?

a) Late binding
b) Static binding.
c) Static Linking.
d) Compile time polymorphism.

Ans:b,c,d


Q-8. WHICH OF THE FOLLOWING STATEMENTS ARE CORRECT FOR RUN-TIME POLYMORPHISM?

a) The overridden base method should be virtual,abstract or override.
b) An abstract method is implicitly a virtual method.
c) An abstract inherited property cannot be overridden in a derived class.
d) Both override method and virtual method must have same access level modifier.


Answer. a),b),d)


Q-9. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE SNIPPET?

using System;
class sample
{
     public sample()
     {
         Console.WriteLine("constructor 1 called");
     }
     public sample(int x)
     {
         int p = 2;
         int u;
         u = p + x;
         Console.WriteLine("constructor 2 called");
     }
}
class Program
{
     static void Main(string[] args)
     {
         sample s = new sample(4);
         sample t = new sample();
         Console.ReadLine();
     }
}

a) constructor 1 called
    constructor 2 called
b) constructor 2 called
    constructor 1 called
c) constructor 2 called
    constructor 2 called
d) error

Check correct option.
Answer. B)



Q-10. WHICH OF THE FOLLOWING KEYWORDS IS USED TO REFER BASE CLASS CONSTRUCTOR TO SUBCLASS CONSTRUCTOR?

a) this
b) static
c) base
d) extend

Check correct option.
Answer. C)

Q-11. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE SNIPPET?

using System;
class sample
{
    int i;
    public sample(int x)
    {
        i = x;
        Console.WriteLine("Tech");
    }
}
class derived : sample
{
    public  derived(int x) :base(x)
    {
        Console.WriteLine("Beamers");
    }
}
class Program
{
    static void Main(string[] args)
    {
        derived k = new derived(12);
        Console.ReadLine();
    }
}

a) TechBeamers
b) 12 Tech
c) Beamers 12
d) Compile time error

Check correct option.
Answer. A)

Q-12. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE SNIPPET?

using System;
class sample
{
     int i;
     public sample(int num)
     {
         num = 12;
         int j = 12;
         int val = num * j;
         Console.WriteLine(val);
     }
}
class sample1 : sample
{
     public sample1(int a) :base(a)
     {
         a = 13;
         int b = 13;
         Console.WriteLine(a + b);
     }
}
class sample2 : sample1
{
     public sample2(int k) :base(k)
     {
         k = 24;
         int o = 6 ;
         Console.WriteLine(k /o);
     }
}
class Program
{
     public static void Main(string[] args)
     {
        sample2 t = new sample2(10);
        Console.ReadLine();
     }
}

a) 4, 26, 144
b) 26, 4, 144
c) 144, 26, 4
d) 0, 0, 0

Check correct option.
 Answer. C)

Q-13. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE SNIPPET?

using System;
class sample
{
    static sample()
    {
        int num = 8;
          Console.WriteLine(num);
    }
    public  sample(int a)
      {
          int val = 10;
          Console.WriteLine(val);
      }
}
class Program
{
    static void Main(string[] args)
    {
        sample s = new sample(100);
        Console.ReadLine();
    }
}

a) 10, 10
b) 0, 10
c) 8, 10
d) 8, 8

Check correct option.
 Answer. C)

Q-14. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE SNIPPET?

using System;
class sample
{
    int i;
    public  sample(int num)
    {
        num = -25;
        int val;
        val = num > 0 ? num : num * -1;
        Console.WriteLine(val);
    }
}
class sample1 :sample
{
    public  sample1(int no) :base(no)
    {
        no = -1000;
        Console.WriteLine((no > 0 ? no : no * -1));
    }
}
class Program
{
    static void Main(string[] args)
    {
        sample1 s = new sample1(6);
        Console.ReadLine();
    }
}

a) 25
    1000
b) -25
    -1000
c) -25
     1000
d) 25
    -1000

Check correct option.
 Answer. A)

Q-15. WHICH OF THE FOLLOWING OPTIONS REPRESENTS THE TYPE OF CLASS WHICH DOES NOT HAVE ITS OWN OBJECTS BUT ACTS AS A BASE CLASS FOR ITS SUBCLASS?


a) Static class
b) Sealed class
c) Abstract class
d) Derived class

Check correct option.
Answer. C)

Q-16. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE SNIPPET?

using System;
namespace TechBeamers
{
    abstract class baseclass
    {
        public int i ;
        public int j ;
        public abstract void print();
    }   
     class derived: baseclass  
     {
         public int j = 5;
         public override void print()
         {
             this.j = 3;
             Console.WriteLine(i + "  " + j);
         }
     }   
     class Program
     {
        static void Main(string[] args)
        {
             derived obj = new derived();
             obj.i = 1;
             obj.print();    
             Console.ReadLine();
        }
     }
}

a) 1, 5
b) 0, 5
c) 1, 0
d) 1, 3

Check correct option.
 Answer. D)



Q-17. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE SNIPPET?


using System;
namespace TechBeamers
{  
    abstract class baseclass
    {
        public int i;
        public abstract void print();
    }   
    class derived: baseclass
    {
        public  int j;
        public int val;
        public override void print()
        {
            val = i + j;
            Console.WriteLine(+i + "\n" + +j);
            Console.WriteLine("sum is:" +val);
        }
    }   
    class Program
    {
        static void Main(string[] args)
        {
            baseclass obj = new derived();
            obj.i = 2;
            derived obj1 = new derived();
            obj1.j = 10;
            obj.print();
            Console.ReadLine();
        }
    }
}

a) 2  10
Sum is: 12
b) 0  10
Sum is: 10
c) 2  0
Sum is: 2
d) 0  0
Sum is: 0

Check correct option.
 Answer. C)


Q-18. WHICH OF THE FOLLOWING REPRESENTS A CLASS THAT INHERITS AN ABSTRACT CLASS BUT IT DOES NOT DEFINE ALL OF ITS FUNCTIONS?

a) Abstract
b) A simple class
c) Static class
d) derived class

Check correct option.
 Answer. A)


Q-19. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE SNIPPET?

using System;
namespace TechBeamers
{
     public abstract class sample
     {
         public int i = 7;
         public abstract void print();
     }   
     class sample1: sample
     {
         public int j;
         public override void print()
         {
             Console.WriteLine(i);
             Console.WriteLine(j);
         }
     }   
     class Program
     {
         static void Main(string[] args)
         {
             sample1 obj = new sample1();
             sample obj1 = new sample1();
             obj.j = 1;
             obj1.i = 8;
             obj.print();
             Console.ReadLine();
         }
     }
}


a) 0, 8
b) 1, 8
c) 1, 7
d) 7, 1

Answer D

Q-20. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE SNIPPET?

using System;
namespace TechBeamers
{
     class sample
     {
         public int i;
         public void print()
         {
             Console.WriteLine(i);
         }
     }   
     class sample1: sample
     {
         public int j;
         public void print()
         {
             Console.WriteLine(j);
         }
     }   
     class Program
     {
         static void Main(string[] args)
         {
             sample1 obj = new sample1();
             obj.j = 1;
             obj.i = 8;
             obj.print();
             Console.ReadLine();
         }
     }
}

a) 8, 1
b) 8
c) 1
d) 1, 8

Answer. C)


















Comments

Popular posts from this blog

Gemini software Dot net interview question for experienced

Gemini Interview questions 4-8 year experienced Dot net professional Gemini Interview questions 4-8 year experienced Dot net professional 1,Asp .net mvc request life cycle. 2,How routing works 3,Where codes for routing are written 4,What is attribute based routing in aap.net Mvc 5,Is multiple routes possible on a single action method. 6,What is action filters. 7,what is authentication and authorization filters 8,What are the types of authentication 8,What is the use of data annotation 9,Can we fire data annotation in client side. 10,What is model binding 11,what are Html helpers

15 Essential jQuery Interview Questions

15 Essential jQuery Interview Questions 15 Essential jQuery Interview Questions 1,Explain what the following code will do: $( "div#first, div.first, ol#items > [name$='first']" ) Ans:This code performs a query to retrieve any element with the id first, plus all elements with the class first, plus all elements which are children of the element and whose name attribute ends with the string "first". This is an example of using multiple selectors at once. The function will return a jQuery object containing the results of the query. 2,What is wrong with this code, and how can it be fixed to work properly even with buttons that are added later dynamically? // define the click handler for all buttons $( "button" ).bind( "click", function() {     alert( "Button Clicked!" ) }); /* ... some time later ... */ // dynamically add another button to the page $( "html" ).append( " Click...

ASP .Net MVC

ASp .Net MVC 1. Explain MVC (Model-View-Controller) in general? MVC (Model-View-Controller) is an architectural software pattern that basically decouples various components of a web application. By using MVC pattern, we can develop applications that are more flexible to changes without affecting the other components of our application. §    “Model”, is basically domain data. §    “View”, is user interface to render domain data. §    “Controller”, translates user actions into appropriate operations performed on model. 2. What is ASP.NET MVC? ASP.NET MVC is a web development framework from Microsoft that is based on MVC (Model-View-Controller) architectural design pattern. Microsoft has streamlined the development of MVC based applications using ASP.NET MVC framework. 3. Difference between ASP.NET MVC and ASP.NET WebForms? ASP.NET Web Forms uses Page controller pattern approach for rendering layout, whereas ASP.NET MVC uses Front con...