What is object-oriented programming (OOP)?
OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object is created in the program to represent a class. Therefore, an object encapsulates all the features, such as data and behavior that are associated to a class. OOP allows developers to develop modular programs and assemble them as software. Objects are used to access data and behaviors of different software modules, such as classes, namespaces, and sharable assemblies. .NET Framework supports only OOP languages, such as Visual Basic .NET, Visual C#, and Visual C++.
How can prevent your class to be inherited further?
You can prevent a class from being inherited further by defining it with the sealed keyword.
What is the index value of the first element in an array?
In an array, the index value of the first element is 0 (zero).
Can you specify the accessibility modifier for methods inside the interface?\
All the methods inside an interface are always public, by default. You cannot specify any other access modifier for them.
Is it possible for a class to inherit the constructor of its base class?
No, a class cannot inherit the constructor of its base class.
Can you declare an overridden method to be static if the original method is not static?
No. Two virtual methods must have the same signature.
Why is the virtual keyword used in code?
The virtual keyword is used while defining a class to specify that the methods and the properties of that class can be overridden in derived classes.
Can you allow a class to be inherited, but prevent a method from being overridden in C#?
Yes. Just declare the class public and make the method sealed.
In which namespace, all .NET collection classes are contained?
The System.Collections namespace contains all the collection classes.
When do you really need to create an abstract class?
We define abstract classes when we define a template that needs to be followed by all the derived classes.
Is it a good practice to handle exceptions in code?
Yes, you must handle exceptions in code so that you can deal with any unexpected situations that occur when a program is running. For example, dividing a number by zero or passing a string value to a variable that holds an integer value would result in an exception.
Can you inherit private members of a class?
No, you cannot inherit private members of a class because private members are accessible only to that class and not outside that class.
Does .NET support multiple inheritance?
.NET does not support multiple inheritance directly because in .NET, a class cannot inherit from more than one class. .NET supports multiple inheritance through interfaces
What is a namespace?
Namespace is considered as a container that contains functionally related group of classes and other types.
Do events have return type?
No, events do not have return type.
A structure in C# can implement one or more interfaces. Is it true or false?
Yes, it is true. Like classes, in C#, structures can implement one or more interfaces.
Can users define their own exceptions in code?
Yes, customized exceptions can be defined in code by deriving from the System.Exception class.