Object Oriented Programming Flashcards

1
Q

What is an Object?

A

A class or struct definition is like a blueprint that specifies what the type can do.

An object is basically a block of memory that has been allocated and configured according to the blueprint.

A program may create many objects of the same class.

Objects are also called instances, and they can be stored in either a named variable or in an array or collection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Encapsulation?

A

The process of binding data members and member functions into a single unit. (Class or Struct)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Abstraction?

A

Abstraction is a process of hiding the implementation details and displaying the essential features.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are Access Specifiers?

A

There are 5 access specifiers,

The public can be accessible outside the class through object reference.

Private can be accessible inside the class only through member functions.

Protected can be just like private but accessible in derived classes also through member functions.

Internal can be visible inside the assembly. Accessible through objects.

Protected Internal can be visible inside the assembly through objects and in derived classes outside the assembly through member functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Inheritance?

A

The process of deriving a new class from an already existing class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can you implement multiple inheritance in C#?

A

Using Interfaces, you can implement multiple inheritance in C#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Polymorphism?

A

When a message can be processed in different ways.

Compile time polymorphism is also known as Overloading. (Overloaded Constructors)

Run time polymorphism also known as Overriding. (Overridden functions in a derived class)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a Constructor?

A

Constructor is a special method of the class that will be automatically invoked when an instance of the class is created.

The main use of constructors is to initialize private fields of the class while creating an instance for the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Destructor?

A

A Destructor is automatically invoked when an object is finally destroyed.

The name of the Destructor is the same as the class and prefixed with a tilde (~).

A Destructor is used to free the dynamically allocated memory and release the resources

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are Namespaces?

A

Allows the creation of a system to organize the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the Virtual keyword?

A

Virtual is used to modify a method, property, indexer, or event declared in the base class and allows it to be overridden in the derived class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the Override keyword?

A

Override is used to extend or modify a virtual/abstract method, property, indexer, or event of the base class into the derived class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the New keyword?

A

New is used to hide a method, property, indexer, or event of the base class into the derived class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between Struct and Class?

A

A struct, cannot be inherited, be abstract, or have a constructor, while a class can.

Structs are generally for small amounts of data while classes are for larger amounts.

Objects of structs do not need to be created with the ‘new’ keyword, while classes do.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is an Interface?

A

An interface looks like a class, but it has no implementation.

The only thing it contains is declarations of events, indexers, methods, and/or properties.

The reason interfaces only provide declarations is because they are inherited by structs and classes, which must provide an implementation for each interface member declared.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is an Abstract class?

A

An abstract class is a special kind of class that can not be instantiated.

An abstract class is only to be sub-classed (inherited from).

The key advantage is that it enforces certain hierarchies for all the sub-classes.

17
Q

What is Operator Overloading?

A

Overloaded operators are functions with special names the keyword operator followed by the symbol for the operator being defined.

18
Q

Can a Method return multiple values at a time?

A

Yes, it is possible that a Method can return multiple values at a time by using the following.

Key-Value pair
Ref or Out parameters
Struct or Class
Tuple

19
Q

What is Constant?

A

It is also known as immutable values.

These are known at compile time and do not change their values at run time in any function or constructor for the life of the application.

20
Q

What is Static?

A

Static members are common to all the objects and they do not get tied to a specific object.

Can be used with classes, fields, methods, properties, operators, events, and constructors, but not with indexers or destructors.

If the static keyword is applied to a class, all the members of the class must be static.

Static methods can only access static members of the same class.

Static properties are used to get or set the value of static fields of a class.

Static constructors cannot be parameterized.

Access modifiers cannot be applied to static constructors. Because it is always a public default constructor which is used to initialize static fields of the class.

21
Q

What is a Property?

A

Properties are members that provide a flexible mechanism to read, write, or compute the values of private fields.

It uses methods to access and assign values to private fields called accessors.