Adsnese

Ad

Thursday, September 27, 2007

C# Interview Questions -1

Question: What’s the implicit name of the parameter that gets passed into the class’ set method?
Answer: Value, and its datatype depends on whatever variable we’re changing.

Question: How do you inherit from a class in C#?
Answer Place a colon and then the name of the base class. Notice that it’s double colon in C++.

Question: Does C# support multiple inheritance?
Answer No, use interfaces instead.

Question When you inherit a protected class-level variable, who is it available to?
Answer: Classes in the same namespace.

Question Are private class-level variables inherited?
Answer: Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.

Question Describe the accessibility modifier protected internal.
Answer: It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in).

Question C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?
Answer: Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.

Question What’s the top .NET class that everything is derived from?
Answer: System.Object.

Question How’s method overriding different from overloading?
Answer: When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.

Question What does the keyword virtual mean in the method definition?
Answer: The method can be over-ridden.

Question Can you declare the override method static while the original method is non-static?
Answer: No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.

No comments:

My Ad

.