Which of the following unary operators can be overloaded?

 1.   true
 2.   false
 3.   +
 4.   new
 5.   is 

  • A) 1,2,3
  • B) 3,4,5
  • C) 2 only
  • D) 3 only
  • E) 5 only

2. A derived class can stop virtual inheritance by declaring an override as  

  • A) inherits
  • B) extends
  • C) inheritable
  • D) not inheritable
  • E) sealed

3. Which of the following keyword is used to change the data and behavior of a base class by replacing a member of a base class with a new derived member?  

  • A) new
  • B) base
  • C) overloads
  • D) override
  • E) overridable

4. Which of the following statements is correct?  

  • A) Operator overloading works in different ways for structures and classes.
  • B) When used as a modifier, the new keyword explicitly hides a member inherited from a base class.
  • C) It is not necessary that all operator overloads are static methods of the class.
  • D) The cast operator can be overloaded.
  • E) None of these

5. Which of the following keyword is used to overload user-defined types by defining static member functions?  

  • A) overload
  • B) op
  • C) operator
  • D) operatoroverload
  • E) udoperator

6. Which of the followings is the correct way to overload + operator?  

  • A)
    public sample operator + ( sample a, sample b )
  • B)
    public static sample operator + ( sample a, sample b )
  • C)
    public abstract sample operator + (sample a, sample b )
  • D)
    public abstract operator + ( sample a, sample b)
  • E)
    All of these

7. Which of the following statements is correct?  

  • A) Static methods can be a virtual method.
  • B) Static methods can be a virtual method.
  • C) It is necessary to override a virtual method.
  • D) When overriding a method, the names and type signatures of the override method must be the same as the virtual method that is being overriden.
  • E) We can override virtual as well as non-virtual methods.

8. Which of the following operators cannot be overloaded? 1. true 2. false 3. new 4. ~ 5. sizeof  

  • A) 1,3
  • B) 2,4
  • C) 1,2,3
  • D) 3,5
  • E) All of these

9. Which of the following modifier is used when a virtual method is redefined by a derived class?  

  • A) override
  • B) overloads
  • C) overridable
  • D) virtual
  • E) base

10. In order for an instance of a derived class to completely take over a class member from a base class, the base class has to declare that member as  

  • A) new
  • B) base
  • C) virtual
  • D) overrides
  • E) overloads

11. Which of the following can be declared as a virtual in a class? 1. Methods 2. Properties 3. Events 4. Fields 5. Static fields  

  • A) 1,2,3
  • B) 3,4,5
  • C) 2,4
  • D) 2,3,5
  • E) none of these

12. Which of the following are necessary for Run-time Polymorphism? 1. The overridden base method must be virtual, abstract or override. 2. Both the override method and the virtual method must have the same access level modifier. 3. An override declaration can change the accessibility of the virtual method. 4. An abstract inherited property cannot be overridden in a derived class. 5. An abstract method is implicitly a virtual method.  

  • A) 1,2,5
  • B) 1,3
  • C) 2,3,4
  • D) 4 only
  • E) 1,2

13. What is Polymorphism.explain diff types.  

Ability to take more than one form is called poymorphism.Diff types are- Compile time/Design time polymorphism this is also called method overloading.The method will have same name but diff parameters. Run time polymorphism this is also called overriding.its achieved by virtual and override keywords

14. What is method overloading ?  

Having different methods with same name but different parameters inn a single class is called method overloading.methods can be overloaded based on following- a)diff no of paramteres. public void method(int a) public void method(int a,int b) b)diff types of parameters. public void method(int a) public void method(float a) c)diff order of parameters. public void method(int a,float b) public void method(float b,int a)

15. When should we use method overloading?  

When you need couple of methods to take different parameters but do the same thing. eg-Draw(circle c),Draw(triangle t)... the basic function is drawing but they draw diff structures. in CLR console.writeline() does the same thing.

16. What is method overriding?  

Its a feature which is used in inheritance chain and it provides its own implementation to an already existing method in base class. its achived by using virtual and override keyword. class A { public virtual void method() { } } class B:A { public override void method() { } } The appropriate methods are invoked at runtime when proper references are allocated

17. Advantages of polymorphism.  

a)invoking child class functions dynamically b)maintenance of code becomes easy.

18. Whats the diff bt new and override keyword in inheritance chain ?  

new keyword completely hides the base class implementation and creates a new method.It can be concluded that the method defined is independent of base class method. override keyword overrides the base class implementation. it helps in existence of different diff versions of method and appropriate version is called dynamically.Objects of derived class will cal this method instead of base class method.

19. Whats the disadvantage of using virtual keyword?  

a)Appropriate function calls are determined only at runtime. b)since virtual keyword is used derived classes may ignore that base class implementations.

20. Why static methods cannot have virtual keyword ?  

The idea of using virtual keyword is to achieve polymorphism i.e calling appropriated functions dynamically at runtime, But static methods are attached to the class names and to invoke them you have to go through the classes. And they are decided at compile time hence there is no point in having virtual keyword to static methods.

.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions