21. Advantages of Inheritance.
a)Code re usability-Public and protected methods can be used in derived classes
b) Extensibility- base class can be extended as per business logic in derived classes.
22. .What are diff types of inheritance?
a) Single inheritance --Class B is derived from base class A. A->B
b)Multiple inheritance ---Class C derives from both A and B. A,B->C
c)Multilevel inheritance--Class B derives from Class base class A.class C derives from B. A->B->C
d)Hybrid inheritance --class B and C derives from same base class A. A->B,C
23. .Is multiple inheritance possible in C#.Why?
a)Its not supported by CLR since its support many diff language and not all languages can have multiple inheritance concept.
b)Because of the complexities involved where method name can clash when two diff classes have same method name.This is resolved by pointers in C++ but its not possible in c#.
Instead interfaces can be used to achieve the same
24. Is circular inheritance possible. like A:B ,B:A ?
25. How do you prevent a class from being inherited ?
a)Make the class as sealed.
b)Add private constructors to the class.
26. Can derive class have public modifier when there are no modifiers specified on the base class?
27. why c# does not support inheritance by structure?
Because structures are mainly used for light weight process. And if they are allowed to be inherited then they have to act as base class which is not possible as they are value types.
28. Does structs inherit from interfaces?
Yes structs can inherit only from interface
29. What do you mean by sealed keyword ?
If you mark a class as sealed it means that you cannot inherit from it but you can create objects of that class
30. can you mark method as sealed ?
Yes.But for a method to be marked as sealed you need to have override keyword also.
31. If we inherit a class do the private variables also get inherited?
Yes, the variables are inherited but cannot be accessed directly by the class interface.
32. What is serialization?
When we want to transport an object through network then we have to convert the object into a stream of bytes. The process of converting an object into a stream of bytes is called Serialization. For an object to be serializable, it should inherit ISerialize Interface.
33. Can a private virtual method be overridden?
No, because they are not accessible outside the class.
34. Describe the accessibility modifier “protected internal”.
Protected Internal variables/methods are accessible within the same assembly and also from the classes that are derived from this parent class.
35. What happens if the inherited interfaces have conflicting method names?
Implement is up to you as the method is inside your own class. There might be problem when the methods from different interfaces expect different data, but as far as compiler cares you’re okay.