101. What is the difference between Shadowing and Overriding?
Overriding redefines only the implementation while shadowing redefines the whole element.
In overriding derived classes can refer the parent class element by using "ME" keyword, but in shadowing you can access it by "MYBASE".
102. Can events have access modifiers?
Yes, you can have access modifiers in events. You can have events with the protected keyword, which will be accessible only to inherited classes. You can have private events only for objects in that class.
103. Why is the virtual keyword used in code?
The Virtual keyword is used in code to define methods and the properties that can be overridden in derived classes.
104. What are constructors and destructors?
Constructors and destructors are special methods.
Constructors and destructors are special methods of every class.
Each class has its own constructor and destructor and are called automatically when the instance of a class is created or destroyed.
The constructor initializes all class members whenever you access the class and the destructor destroys them when the objects are not required anymore.
105. How can we suppress a finalize method?
GC.SuppressFinalize()
106. Does C# support a variable number of arguments?
Yes, using the params keyword.
The arguments are specified as a list of arguments of a specific type, e.g., int. For ultimate flexibility, the type can be object.
The standard example of a method which uses this approach is System.console.writeLine().
107.Which method will you call to start a thread?
Start
108. What is Generic?
Generic help us to create flexible strong type collection.
Generic basically seperate the logic from the datatype in order maintain better reusability, better maintainability etc.
109. What are the different types of polymorphism?
There are two types of polymorphism. They are:
Compile time Polymorphism
Run time Polymorphism
110. What is the difference between compile time polymorphism and run time polymorphism?
Compile time Polymorphism
Compile time Polymorphism also known as method overloading.
Method overloading means having two or more methods with the same name but with different signatures.
Run time Polymorphism
Run time Polymorphism also known as method overriding.
Method overriding means having two or more methods with the same name , same signature but with different implementation.
111. Which namespace enables multithreaded programming in XML?
System.Threading
112. Can we declare a block as static in c#?
No, because c# doesnot support static block, but it supports static method.
113. Can we declare a method as sealed?
In C# a method can't be declared as sealed. However when we override a method in a derived class, we can declare the overridden method as sealed. By declaring it as sealed, we can avoid further overriding of this method.
114. What Command is used to implement properties in C#?
get & set access modifiers are used to implement properties in c#.
115. What is static member?
The member defined as static which can be invoked directly from the class level, rather than from its instance.
116. What is the syntax to inherit from a class in C#?
When a class is derived from another class, then the members of the base class become the members of the derived class.
The access modifier used while accessing members of the base class specifies the access status of the base class members inside the derived class.
The syntax to inherit a class from another class In C# is as follows:
class MyNewClass : MyBaseClass
117. What is a basic difference between the while loop and do while loop in C#?
The while loop tests its condition at the beginning, which means that the enclosed set of statements run for zero or more number of times if the condition evaluates to true. The do while loop iterates a set of statements at least once and then checks the condition at the end.
118. What is the main difference between a subprocedure and a function?
Subprocedures do not return a value, while functions do.
119. What are sealed classes in c#?
The sealed modifier is used to prevent derivation from a class.
A compile time error occurs if a sealed class is specified as the base class of another class.
120. What is the difference between class and an Interface?
Abstract classes can have implementations for some of its members, but the interface can't have implementation for any of its members.
Interfaces cannot have fields where as an abstract class can have fields.
An interface can inherit from another interface only and cannot inherit from an abstract class, where as an abstract class can inherit from another abstract class or another interface.
A class can inherit from multiple interfaces at the same time, where as a class cannot inherit from multiple classes at the same time.
121. What is the difference between an abstract method & virtual method?
An Abstract method does not provide an implementation and forces overriding to the deriving class (unless the deriving class also an abstract class), where as the virtual method has an implementation and leaves an option to override it in the deriving class. Thus Virtual method has an implementation & provides the derived class with the option of overriding it. Abstract method does not provide an implementation & forces the derived class to override the method.
122. What is Static Method?
It is possible to declare a method as Static provided that they don't attempt to access any instance data or other instance methods.
123. What is a New modifier?
The new modifier hides a member of the base class. C# supports only hide by signature.
124. What are the advantages of get and set properties in C#?
The get property accessor is used to return the property value.
The set property accessor is used to assign a new value.
125. What are the difference between const and readonly?
A const can not be static, while readonly can be static.
A const need to be declared and initialized at declaration only, while a readonly can be initialized at declaration or by the code in the constructor.
A const's value is evaluated at design time, while a readonly's value is evaluated at runtime.

0 comments:
Post a Comment