Question 81 – What are the Types of Inheritance?
- Implementation inheritance refers to the ability to use a base class’s properties and methods with no additional coding.
- Interface inheritance refers to the ability to use just the names of the properties and methods, but the child class must provide the implementation.
- Visual inheritance refers to the ability for a child form (class) to use the base forms (class) visual representation as well as the implemented code.
Question 82 – What is Multiple Inheritance?
C# does not support multiple implementation inheritance. A class cannot be derived from more than one class, However, a class can be derived from multiple interfaces.
Question 83 – What are the examples of Multiple Inheritance?
Imagine a class named TransmitData, whose function is to transmit data, and another class named ReceiveData, whose function is to receive data. Now imagine that you want to create a class named SocketPort, whose function is to transmit and receive data. In order to accomplish this, you would want to derive SocketPort from both TransmitData and ReceiveData.
Question 84 – What are the Advantages of Inheritance?
- Once a behavior (method) or property is defined in a super class(base class),that behavior or property is automatically inherited by all subclasses (derived class).
- Code reusability increased through inheritance.
- Inheritance provide a clear model structure which is easy to understand without much complexity Using inheritance, classes become grouped together in a hierarchical tree structure Code are easy to manage and divided into parent and child classes.
Question 85 – What is an Encapsulation?
- Encapsulation is a process of hiding all the internal details of an object from the outside world.
- Encapsulation is the ability to hide its data and methods from outside the world and only expose data and methods that are required
- Encapsulation gives us maintainability, flexibility and extensibility to our code.
- Encapsulation makes implementation inaccessible to other parts of the program and protect from whatever actions might be taken outside the function or class.
- Encapsulation provides a way to protect data from accidental corruption
- Encapsulation hides information within an object
- Encapsulation is technique or process of making fields in a class private and providing access to the fields using public methods
- Encapsulation allows us to create a “black box” and protects an objects internal state from corruption by its clients.
- The idea of encapsulation comes from the need to cleanly distinguish between the specification and the implementation of an operation and the need for modularity.
Question 86 – What are the examples of Encapsulation?
- Let’s say you have an object named Bike and this object has a method named start(). When you create an instance of a Bike object and call its start() method you are not worried about what happens to accomplish this, you just want to make sure the state of the bike is changed to ‘running’ afterwards. This kind of behavior hiding is encapsulation and it makes programming much easier.
- Video Recorder, which has a record, play, pause buttons is another example of encapsulation, so VCR is encapsulated into a single object where the internals can change but stays the same for users interface point of view.
- Medical Capsules i.e. one drug is stored in bottom layer and another drug is stored in Upper layer these two layers are combined in single capsule.
Question 87 – What is an Abstraction?
- Abstraction means to show only the necessary details to the client of the object.
- Abstraction is about paying attention to the details that are relevant and ignoring the rest.
- It refers to act of representing essential features without including background details / explanations.
Question 88 – What are the examples of Abstraction?
- Do you know the inner details of the Monitor of your PC? What happen when you switch ON Monitor? No Right, Important thing for you is weather Monitor is ON or NOT.
- When you change the gear of your vehicle are you really concern about the inner details of your vehicle engine? No but what matter to you is that Gear must get changed that’s it!!
- Let’s say you have a method “CalculateSalary” in your Employee class, which takes EmployeeId as parameter and returns the salary of the employee for the current month as an integer value. Now if someone wants to use that method. He does not need to care about how Employee object calculates the salary? An only thing he needs to be concern is name of the method, its input parameters and format of resulting member. This is abstraction; show only the details which matter to the user.
- TV Remote Button in that number format and power buttons and other buttons there just we are seeing the buttons, we don’t see the button circuits .i.e buttons circuits and wirings all are hidden.
Question 89 – Difference between Encapsulation and Abstraction ?
Encapsulation |
Abstraction |
Hiding the internal details or mechanics of how an object does something. |
It focus on what the object does instead of how it does it. |
Binding data and member functions together inside a single unit. |
Hiding the complexities of your type from outside world. |
Eg: VCR Example |
Eg: Monitor Example |
Question 90 – What is an Abstract Class?
- It is a class that cannot be instantiated, it exists extensively for inheritance and it must be inherited.
- Abstract classes cannot be used to instantiate objects; because abstract classes are incomplete
- Abstract classes may contain only definition of the properties or methods.
- Derived classes that inherit the abstract class needs to implements it’s properties or methods.
- An abstract class is essentially a blueprint for a class without any implementation.
- An abstract class is a class that must be inherited and have the methods overridden.
- An abstract class cannot be a sealed class.
- An abstract method cannot be private.
- An abstract member cannot be static.
- An abstract method cannot have the modifier virtual. Because an abstract method is implicitly virtual.
- The access modifier of the abstract method should be same in both the abstract class and its derived class. If you declare an abstract method as protected, it should be protected in its derived class. Otherwise, the compiler will raise an error.
Disclaimer – F5debug Interview Questions & Answers Series:
You may recopy extracts from these pages (“the material”) to individual third party websites or to any intranet websites, but only if:
You acknowledge www.f5debug.net as the source of the material. Such acknowledgment should include reference to www.f5debug.netin the copy of the material and should also include “© Karthikeyan Anbarasan, www.f5debug.net “. You inform the third party that these conditions apply to him/her and that he/she must comply with them.
No Comments
Decouvrir notre excellent post : <a href="http://medicalcybrarian.com">Acheter e-cigarette</a><br/>