oops concept in .net interview questions and answers, object oriented programming coneps in .net
Hi welcome Back to Dotnet section today i would like to share more .net interview questions and answers on Topic oops.
1). what are the different types of inheritance.
Inheritance in OOP is of four types:
- Single inheritance - Contains one base class , one derived class
- Hierarchical inheritance - Contains one base class and the multiple derived classes of the same base class
- Multilevel inheritance - Contains a class derived from the derived class
- Multiple inheritance - Contains several base classes and the derived class
2)What do you mean by term data encapsulation?
Data
encapsulation is a concept of binding data and code in single unit
called object and hiding all implementation details of a class from
the user. It prevents unauthorized access of data and restricts user
to use the necessary data only.
3). What is the difference between procedural and object-oriented programming Explian?
Procedural
programming is based upon modular approach in which the larger
programs are broken into procedures. Each procedure is a set of
instructions that are executed one after another. whereas OOP
is based upon the objects. An object consists of various elements such as
methods and variables.
And morever Access modifiers are not used in procedural programming, which implies that the entire data can be accessed freely anywhere in the program. In OOP, you can specify the scope of a particular data by using access modifiers - public, private, internal, protected, and protected internal.
Interface
And morever Access modifiers are not used in procedural programming, which implies that the entire data can be accessed freely anywhere in the program. In OOP, you can specify the scope of a particular data by using access modifiers - public, private, internal, protected, and protected internal.
49. What are different ways method can be overloaded?
The different ways to overload a method are as follows:
- By changing number of parameters used
- By changing order of parameters
- By using different data types for parameters
4. Give the difference between an abstract class and an interface.
Abstract Class:
- class can extend only one abstract class
- members of abstract class can be private as well as protected.
- Abstract classes should have the subclasses
- Any class can extend from an abstract class.
- Methods in a abstract class can be abstract as well as concrete.
- There can be a constructor for the abstract class.
- The class extending abstract class may or may not implement any of its method.
- abstract class can implement methods.
Interface
- class can implement several interfaces
- An interface can only have the public members.
- Interfaces must have implementations by classes
- Only an interface can extend from another interface.
- All methods in an interface should be abstract
- Interface does not have a constructor.
- All methods of interface need to be implemented by a class implementing that interface.
- Interfaces cannot contain body of th eany of its method.
5. When do you really need to create an abstract class explain?
We define abstract classes when we define the template that needs to be followed by all derived classes.
ConversionConversion EmoticonEmoticon