Tuesday, February 24, 2009

OOPS WRT DOTNET

1. What is OOPS?
ANS: Object oriented programming allows decomposition of a problem into number of small entities called objects and then it builds data and function around these objects.
.It help in programming approach in order to built robust, user friendly and efficient software’s and provide the efficient way to maintain real world software’s.
2. What Is a Object.
It is a basic unit of a system. An object is an entity that has attributes, behavior, and
identity. Objects are members of a class. Attributes and behavior of an object are defined
by the class definition
3. 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’s a comprehensive data type which represents a blue print
of objects. It’s a template of object.
(or)
In .NET languages, classes are templates used for defining new types. Classes describe both the properties and behaviors of objects. Properties contain the data that are exposed by the class. Behaviors are the functionality of the object, and are defined by the public methods (also called member functions) and events of the class. Collectively, the public properties and methods of a class are known as the object interface. Classes themselves are not objects, but instead they are used to instantiate (i.e., create) objects in memory.
4.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 Honda car
object with 100 km speed and urgent brakes.
5. Interface?
ANS: The set of properties, methods, indexers, and events exposed by an object that allow other objects to access its data and functionality.
It is class which contain all implemented methods (can also call them abstract methods) we will implement these methods in derived class of interface. i.e., as interface not inherited but implemented.
6. Why can’t you specify the accessibility modifier for methods inside the interface?
They all must be public, and are therefore public by default.
7. Can you inherit multiple interfaces?
Yes. .NET does support multiple interfaces
8. What happens if you inherit multiple interfaces and they have conflicting method names?
It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.
To Do: Investigate
9. Why can’t you specify the accessibility modifier for methods inside the interface?
They all must be public, and are therefore public by default.

10. Abstract?

ANS: A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.
It refers to the act of representing essential features without including the background details or explanation.
11. When do you absolutely have to declare a class as abstract?
1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
2. When at least one of the methods in the class is abstract.
12. What’s the difference between an interface and abstract class?
In an interface class, all methods are abstract - there is no implementation. In an abstract class some methods can be concrete. In an interface class, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers
13. Inheritance?
ANS: Is a process in which objects of one class can acquire the properties of another class.
It provides the ides of reusability.
In other words we can say “the ability of a class to be created from another class.”
14. What is the syntax to inherit from a class in C#?
Place a colon and then the name of the base class.
Example: class MyNewClass : MyBaseClass
15. Can you prevent your class from being inherited by another class?
Yes. The keyword “sealed” will prevent the class from being inherited.
16. Can you allow a class to be inherited, but prevent the method from being over-ridden?
Yes. Just leave the class public and make the method sealed.
17.If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?
Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

18. Polymorphism?

ANS: Mean by more than one form. Ability to provide different implementation based on different no. type of parameters. A method behaves differently based on the different input parameters. It will not depend on return types.
In General an operation can exhibit different behavior in different instances.
Pure-Polymorphism:
Make a method abstract/virtual in base class, override it in derived class.
19. Encapsulation?
ANS: The wrapping of data and methods together into a single unit (class) is called encapsulation.
Binding of attributes and behavior. Hiding the implementation and exposing
20.What is the difference between a Struct and a Class?
Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval. Another difference is that structs cannot inherit.
21. Operator Overloading?
ANS: Operator overloading is the ability to tell the compiler how to perform a certain operation when its corresponding operator is used on one or more variables.
Operator overloading is used to give special meaning to the commonly used operators (such as +, -, * etc.) with respect to a class. By overloading operators, we can control or define how an operator should operate on data with respect to a class.
22. Method Overloading?
ANS: Method overloading is having methods in a class that have same method name but different in parameters. It is a form of Polymorphism.
23. What does the keyword “virtual” declare for a method or property?
The method or property can be overridden.
24. How is method overriding different from method overloading?
When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class.

25. Can you declare an override method to be static if the original method is not static?

No. The signature of the virtual method must remain the same. (Note: Only the keyword virtual is changed to keyword override)
26. What are the different ways a method can be overloaded?
Different parameter data types, different number of parameters, different order of parameters.

No comments:

Post a Comment

 
Computers Business Directory - BTS LocalAdd to Technorati Favorites