Rank: Member Groups: Member
Joined: 3/8/2008 Posts: 5
|
17.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.
18. 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.
19. Why can’t you specify the accessibility modifier for methods inside the interface?
They all must be public, and are therefore public by default.
20. Describe the accessibility modifier “protected internal”.
It is available to classes that are within the same assembly and derived from the specified base class.
21. 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 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.
22. What are the different ways a method can be overloaded?
Different parameter data types, different number of parameters, different order of parameters.
23. How do you mark a method obsolete?
[Obsolete]
public int Foo()
{…}
or
[Obsolete(\”This is a message describing why this method is obsolete\”)]
public int Foo()
{…}
24. What is a sealed class?
It is a class, which cannot be subclassed. It is a good practice to mark your classes as sealed, if you do not intend them to be subclassed.
25. How do you prevent a class from being inherited?
Mark it as sealed.
26. Can you inherit from multiple base classes in C#?
No. C# does not support multiple inheritance, so you cannot inherit from more than one base class. You can however, implement multiple interfaces.
|