Part1 - Tutorials EU Flashcards
What is a class?
A class is a template to create an object. It contains properties as well as methods.
What are the key concepts of object-oriented programming?
ncapsulation, abstraction, polymorphism, and inheritance are the main concepts of object-oriented programming.
Explain Encapsulation
Encapsulation is a process of wrapping function and data members together in a class. It is like a capsule, a single unit.
Encapsulation is to prevent the unauthorized or unwanted change of data from outside of the function.
For example, we define the properties of class as private. This prevents form direct access of provate members. But we can provide a way to set and get using getters or setters.
What is a constructor, and what are its different types?
A constructor is like a method with the same name as the class, but it is a unique method. Even if it is not created, the compiler creates a default constructor in memory at the time of creating an object of the class.
The constructor is used to initialize the object with some default values.
Default constructor, parameterized constructor, copy constructor, static constructor, private constructor are different constructor types.
What is a private constructor?
Private Constructor prevents the creation of classes. It also prevents the inhertance of the class.
Usually used in the Singleton pattern where constructor is a private and we will define a public method getInstance(). In this method if instance is not created we will create and return it.
What is a destructor in C#?
The Destructor clears out the memory to free up resources. It is managed automatically by the garbage collector. System.GC.collect() is called internally for this purpose. However, if required, it can be done explicitly using a destructor.
Is C# code managed or unmanaged code?
C# is managed code because Common language runtime compiles the code to Intermediate language.
What are value types and reference types?
We can categorize variables into value type and reference type.
Variables of value type contain the value directly while the variable of a reference type contains the reference of the memory address where the value is stored actually in the memory.
For example bool, byte, int, char, and decimal are value type
And String, class, delegates are examples of reference types.
What are namespaces, and is that compulsory?
A namespace is a way of organizing classes of the same group or functionality under the same name. We can call it a module. Although it is not compulsory to put class in a namespace.
What is an interface?
An interface is another form of an abstract class that has only abstract public methods, and these methods only have the declaration and not the definition. A class implementing the interface must have the implementation of all the methods of the interface.
ow to implement multiple interfaces with the same method name in the same class?
if we want to implement multiple interfaces with the same method name, then we cannot directly implement the body of the function. We have to explicitly provide the name of the interface to implement the body of the method. In this way, the compiler decides which interface methods we are referring to, and this resolves the issue.
What is the virtual method, and how is it different from the abstract method?
A virtual method must have a default implementation, and We can override this virtual method using the override keyword in the derived class.
The abstract method is without implementation, and it is created inside the abstract class only. In the case of an abstract class, the class derived from the abstract class must have an implementation of that abstract method.
What is method overloading and method overriding?
Method overloading is when we have a function with the same name but a different signature.
Method overriding is when we override the virtual method of a base class in the child class using the override keyword.
Both, method overloading and overriding are a type of polymorphism.
Can we use “this” with the static class?
No, we cannot use “this” with the static class because we can only use static variables and static methods in the static class.
What is the difference between constants and read-only?
Constant variables have to be assigned a value at the time of declaration only, and we cannot change the value of that variable throughout the program.
We can assign the value to the read-only variable at the time of declaration or in a constructor of the same class.
What are Abstract class?
AN abstract class is a partially defined parent class.
For example, we have a Customer base class. This base class has a method, applyDiscount. We have two derived class GoldCustomer and SilverCustomer. Without Abstract class, we can use overriding and make the base’s applyCoupon as virtual. But this has a drawback. What if somebody calls it. Hence we can make this as abstract method. WHen we have a abstratc method, the class should be abstract.
ARe abstract methods virtual?
Yes
Ca n we create an instance of an abstract class?
No
Is it compulasary to implement abstract methods?
Yes
can we write a logic in interface
No
Can we define methods as private in interface?
No
Whats the difference between a .NET and C#?
.NET is a framework and C# is a programming language, that’s what interviewer wants to hear.
.NET framework has collection of ready-made libraries. So for example you want List, Dictionary it has
“System.collections.dll” , you want to make HTTP calls it has “System.Net.Http.dll” and so on.
While C# is programming language it has syntax, grammar, it has those “for loops”,” IF” conditions and so
on.
C# language invokes / orchestrates .NET framework libraries to create an application.