OOPS



1.
 
What will be the size of the object created by the following C#.NET code snippet?

 namespace LazyQuestionsConsoleApplication
{     
   class Baseclass   
     {        
        private int i;         
       protected int j;         
       public int k;   
    }   

  class Derived: Baseclass    
   {        
     private int x;  
     protected int y;      
    public int z;   
  }    
 class MyProgram   
  {        
     static void Main (string[ ] args)  
      {          
        Derived d = new Derived();    
      }   
  } 
}
 

  • A) 24 bytes
  • B) 12 bytes
  • C) 20 bytes
  • D) 10 bytes
  • E) 16 bytes


2. Which of the following should be used to implement a 'Has a' relationship between two entities?  

  • A) Polymorphism
  • B) Inheritance
  • C) Templates
  • D) Containership
  • E) Encapsulation


3. Which of the following are reuse mechanisms available in C#.NET? 1. Inheritance 2. Encapsulation 3. Templates 4. Containership 5. Polymorphism  

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


4. 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
    



5.
Which of the following statements are correct about the C#.NET code snippet given below?

 DesignGoDynamic c;
c = new  DesignGoDynamic ();

1.    It will create an object called DesignGoDynamic .
2.    It will create a nameless object of the type DesignGoDynamic .
3.    It will create an object of the type DesignGoDynamic on the stack.
4.    It will create a reference c on the stack and an object of the type DesignGoDynamic on the heap.
5.    It will create an object of the type DesignGoDynamic either on the heap or on the stack depending on the size of the object. 
 

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


6. What is Object Oriented Programming?  

It is a problem solving technique to develop software systems. It is a technique to think real world in terms of objects. Object maps the software model to real world concept. These objects have responsibilities and provide services to application or other objects.


7. What is a Class?  

A class describes all the attributes of objects, as well as the methods that implement the behavior of member objects. It is a comprehensive data type, which represents a blue print of objects. It is a template of object.


8. What is an Object?  

They are instance of classes.It is a basic unit of a system. An object is an entity that has attributes, behavior, and identity. Attributes and behavior of an object are defined by the class definition.


9. What is the relation between Classes and Objects?  

They look very much same but are not same. Class is a definition, while object is a instance of the class created. Class is a blue print while objects are actual objects existing in real world. Example we have class CAR which has attributes and methods like Speed, Brakes, Type of Car etc. Class CAR is just a prototype, now we can create real time objects which can be used to provide functionality. Example we can create a Maruti car object with 100 km speed and urgent brakes.


10. What is Communication using messages?  

When application wants to achieve certain task, it can only be done using combination of objects. A single object cannot do all the task. Example if we want to make order-processing form. We will use Customer object, Order object, Product object, and Payment object to achieve this functionality. In short, these objects should communicate with each other. This is achieved when objects send messages to each other.


11. Explain Object lifetime.  

All objects have lifetime. Objects are created, and initialized, necessary functionalities are done and later the object is destroyed. Every object have there own state and identity, which differ from instance to instance.


12. Explain Association.  

This is the simplest relationship between objects. Example every customer has sales. So Customer object and sales object have an association relation between them.


13. What is Aggregation?  

This is also called as composition model. Example in order to make a “Accounts” class it has use other objects example “Voucher”, “Journal” and “Cash” objects. Therefore, accounts class is aggregation of these three objects.


14. what are abstract classes?  

Following are features of a abstract class:-
• We can not create a object of abstract class
• Abstract class is designed to act as a base class (to be inherited by other classes).Abstract class is a design concept in program development and provides a base upon which other classes are built.
• Abstract classes are similar to interfaces. After declaring an abstract class, it cannot be instantiated on its own, it must be inherited.
• In C# we have “Abstract” keyword.
• Abstract classes can have implementation or pure abstract methods, which should be implemented in the child class.


15. Can events have access modifiers?  

Events are always public as they are meant to serve every one-register ing to it. But you can access modifiers in events. You can have events with protected keyword, which will be accessible only to inherited classes. You can have private events only for object in that class.


16. If we inherit a class do the private variables also get inherited?  

Yes, the variables are inherited but cannot be accessed directly by the class interface.


17. What is the different accessibility levels defined in .NET?  

Following are the five levels of access modifiers:-
• Private:- Only members of class have access.
• Protected:- All members in current class and in derived classes can access the variables.
• Internal :- Only members in current project have access to the elements.
• Protected internal :- All members in current project and all members in derived class can access the variables.
• Public: - All members have access in all classes and projects.


18. Can you prevent a class from overriding?  

If you define a class as “Sealed” in C # you cannot inherit the class any further.


19. What is the difference between Class and structure’s?  

Following are the key differences between them:-
• Structures are value types and classes are reference types. So structures use stack and classes use heap.
• Structures members cannot be declared as protected, but class members can be. You cannot do inheritance in structures.
• Structures do not require constructors while classes require.
• Objects created from classes are terminated using Garbage collector. Structures are not destroyed using GC.


20. What are similarities between Class and structure?  

Following are the similarities between classes and structures:-
• Both can have constructors, methods, properties, fields, constants, enumerations, events, and event handlers.
• Structures and classes can implement interface.
• Both of them can have constructors with and without parameter.
• Both can have delegates and events.


.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions