1. What is the output of the following code?
public class Test : Sample, ISample
public interface ISample
int Add(int a, int b);
public class Sample
public int Add(int a, int b)
return a + b;
Ans. works fine. Since the method which is in interface is implemented in other class it will not show error.
Otherwise compile error will be shown.
2. Explain Static Class Members?
Ans. A non-static class can contain static methods, fields, properties, or events.
The static member is callable on a class even when no instance of the class has been created. The static member is always accessed by the class name, not the instance name. Static methods and properties cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it is explicitly passed in a method parameter.
Only one copy of a static member exists, regardless of how many instances of the class are created.
3. Types of Constructors</strong></p>
Ans. Basically constructors are 5 types those are
4.Explain use of Abstract and Sealed Classes in C#?
Ans. Abstract: This keyword enables you to create classes and class members that are incomplete and must be implemented in a derived class.
Sealed : This keyword enables you to prevent the inheritance of a class or certain class members that were previously marked virtual.
5. What are the advantages of properties in C#?
Ans. Following are the advantages of the properties in c#,
1. Properties can validate data before allowing a change.
2. Properties can transparently expose data on a class where that data is actually retrieved from some other source such as a database.
3. Properties can take an action when data is changed, such as raising an event or changing the value of other fields.
6. What are the 2 broad classifications of fields in C#?
1. Instance fields
2. Static fields
7. What is the difference between a constant and a static readonly field?
Ans. A static readonly field is very similar to a constant, except that the C# compiler does not have access to the value of a static read-only field at compile time, only at run time.
8. What are instance fields in C#?
Ans. Instance fields are specific to an instance of a type.
If you have a class T, with an instance field F, you can create two objects of type T, and modify the value of F in each object without affecting the value in the other object.