• What is OOP?
OOP (Object Oriented Programming) is a programming technique in which programs are written on the bases of the object.
• What is a Class?
Class is a type. A class is a collection of objects of a similar type. Once a class is defined, any number of objects can be created which belong to that class. A class is a blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind. Class can also called the specifications of the objects.
• What is Object?
Object is an encapsulation of fields and related behaviors of a particular type (class).
• Pillars of OOP
i)Inheritance ii)Polymorphism iii)Encapsulation iv)Abstraction
• What is Inheritance? Real time Example?
Inheritance is an important concept of OOP in which one (child) class inherited all the members of the other (base, parent) class and may have also its own, e.g. Vehicle and Car relation, is a relationship defines the inheritance like car is a vehicle. Major benefit of inheritance is reuse.
Real time Example:
It is very simple. We ourselves are an example of this. Technically, we
are derived from our parents and they are derived from grandparents and so on.
But there is a difference. The derived class is always bigger than the base
class but in our case, the child is always smaller than parents.
• What is Polymorphism? Real Time Example?
Polymorphism means many forms. For example one method of parent class with same name is use in different child or inherited classes with different functionality with slightly changing in method. There are mainly two types of polymorphism i)Overloading, ii)Overriding
Real time Example:
Let’s take the example of some words which can be used in different situations with different meaning. 'Watch' - watch can be used as a verb as well as a noun. "He is wearing a watch." In this it is used as a noun. "Watch your actions." In this it is used as a verb. Thus we see that the same word can be used in different situations differently. Likewise same operators or function names are used with various meanings in various situations.
• What is Encapsulation? Real Time Example?
Packing in one unit like capsule of a medicine. Remember Encapsulation is not a Data Hiding but leads to Data Hiding. Example include the object of the particular class can only use the data members of the class, any other object of different class cannot use it directly.
Real time Example:
How do u think a car runs? Is there only steering, brake and whatever you are able to see directly?? NO. There is many more parts inside to make it run. Engine, wires, tank etc. but we don't see it. Thus we can say that car is basically a collective unit of many parts which help it to run. Same way, in classes, we have functions and data members wrapped up together.
• What is Abstraction? Real Time Example?
Hide the detail from the user, e.g. the console class having multiple methods. The user use it only and not seen the code of the console class. Private Fields is an example of abstraction. Real life object have many type of data members, Capture only relevant details that are relevant to current perspective. In interview, the interviewer only focusing your abilities that he or she needed indeed. Abstraction can be very useful in Analysis and Design.
Real time Example:
Let’s continue with the above example for encapsulation. Suppose you start going for driving classes. Does the instructor teach you about the functioning of the engine?? NO. Why?? Because he knows that for driving, you don't need to know about the functioning of engine. All those are kept hidden from you.
• What is Overloading?
Overloading means that same name of method used with different parameters, sequence of parameters, number of parameters, types of parameters.
• What is Overriding?
Providing a different implementation for functionality of an inherited method is called method overriding.
Following are some basic rules for method overriding in .NET
♦Method must be inherited.
♦Signature (Name + Parameters of a method (type, kind (out, ref))) prams parameter is not included, return type and access modifier of inherited method and overridden method must be same/match.
♦Inherited method must be declared with the virtual or abstract keyword.
♦Override method must be declared with the override keyword.
• What is IL?
IL/MSIL/CIL- IL code is a CPU independent partially compiled code. It's partially compiled because we do not know in what kind of environment .Net code will run and on runtime IL Code will compile to machine code using the environmental properties (CPU, OS, machine configuration etc).
• What Type of Code that Language Compiler generates, then What JIT Compiler Generate?
MSIL (IL) is generated by .NET Complier from source code of any .NET language. Then this IL is compiled under JIT compiler that generate Machine Native code that is understand by underlying Operation System.
• Difference between Destructor and Garbage Collector
a. The garbage collector is a part of the .NET environment that keeps track of objects and makes sure that objects are removed from memory when they are no longer needed.
b. A destructor is a part of a class design. It's the opposite of a constructor. When you declare it the GC will call it when it destroys an object.
c. The destruct or is a special member function which is invoked when an object is destroyed. It is the last method run by a class. The garbage collector is part of the framework, automatically manages memory, and non-deterministically collects unreferenced objects to avoid memory leaks.
d. Both are used to destroy unallocated object in the memory.
e. Destroy are called CLR (Common Language Run time) and Garbage Collection called by .net Framework
(Practice Makes a Man Perfect)
No comments:
Post a Comment