In fact this one is the basic but very important .NET interview questions asked in almost every interview. An interviewer expects that every candidate should know and answer it. So if you are not sure about it so read the following answer thoroughly and get clear your fundamental related to OOPS.
- Abstraction: - Abstraction filters un-necessary information from the user’s perspective. It just gives enough information to the user rather than giving him unnecessary information by which he can get confused. Abstraction can be different from different user perspective. For instance below figure 'Abstraction perspective' shows how a simple user looks at a television and how a TV mechanic looks at the television. From a simple user perspective he only needs to start, stop, change channels and control volume. But when a TV mechanic looks at the box he is concerned with details like CRT, Electrical Components, Wires, connection, cooling fan etc. So abstraction is about two things one is show only what is needed and second the need should be from end users perspective.
Figure: - Abstraction Perspective
Ok, now how does that fit in to the software world? When we design components we should know what type of user will be using the component. Figure ‘Abstraction in action’ shows how the customer components when has different view of abstraction for the internal and external developer.
Figure: - Abstraction in Action
- Encapsulation: - Encapsulation separates an object interface from its implementation. It hides internal implementation details from the users. You can get a better feel by looking at the figure ‘Encapsulation and Abstraction’. It shows a simple stock class which allows a user to add and remove products from the stock. It also has a restock and alert in case products are out of stock. End user is only exposed to operations like ‘addstock’,’removestock’ and get the current level of the stock. He is completely isolated from auto functionalities like how the restock operation takes place. These operations are encapsulated from the end user perspective.
Note :- Abstraction means to expose the necessary functionalities while encapsulation means to hide the complexity. They both complement each other, but there is a huge difference in terms of thinking approach. In interviews ‘difference between abstraction and encapsulation’ is one of the favorites questions among interviewers. So understand the concept fundamentally as you can get in to long talks of confusion with the interviewer.
Figure: - Encapsulation and Abstraction
In java or C# encapsulation is achieved by using private, public and protected access modifiers.
- Inheritance: - OOPS is all about mapping with real world. One of the relationships in real world is parent child relationship. Inheritance is a methodology by which you can form new classes using existing classes as base. For instance figure ‘Inheritance in action’ shows we have created a parent class called as ‘ClsDisplay’. We can inherit from ‘clsDisplay’ and create bold and italic display classes.
Figure: - Inheritance in action
- Polymorphism: - Polymorphism means one object can exist in different forms. It refers to ability of the object to take different forms depending on situations. For instance we can use the ‘clsDisplay’ object to point to italic or a bold display object. So depending on the situation the parent class ‘clsDisplay’ can morph/change to any other form.
Figure: - Polymorphism in action
See more on OOPS in video from describing implementation of Aggregation, Association and Composition as follows: -
Visit to get more stuff on interview questions and answers for .NET
Also visit for more author’s other blogs on Most asked .NET interview questions
write a comment