OOP-Object Orientated Programming Flashcards

1
Q

What are the benefits of OOP?

A

Data and functions combined, better modularity, low coupling, easier to re-use and closely modelling to the real-world.

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

What are the four pillars of OOP?

A

Abstraction, Encapsulation, Inheritance, Polymorphism

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

What is Polymorphism

A

Polymorphism is the ability of objects of different types to provide a unique interface for different implementations of methods.

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

What is Inheritance?

A

It is a mechanism where you can derive a from another class for a hierarchy of classes that share a set of attributes and methods.

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

What is Encapsulation?

A

The idea of restricting access to the methods in the class. Hiding it’s data by using properties {get; set;} or declare fields/variables as private.

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

What is abstraction?

A

The main goal is to handle complexity by hiding unnecessary details from the user. It achieved with either abstract classes or interfaces

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

What is a struct?

A

It’s is a user-defined data type that can store multiple related items. Structs are similar to classes used in object oriented programming

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

What is the difference between a struct and class

A

Structs are value types whereas Classes are reference types.

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

What is a backing field?

A

Properties use backing fields automatically to get and set. A backing field is therefore implicitly hidden. If you want to put logic in your properties, then you have to explicitly state them beforehand.

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

What is object initialisation?

A

A way to initialise an object of a class or collection. Object initialisers allow you to assign values to the fields or properties at the time of creating an without invoking a constructor.

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

What does the static keyword mean?

A

Static means that the particular member belongs to a type itself, rather than to an instance of that type.

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

What is an abstract method? An abstract class?

A

Abstract classes cannot be instantiated, but they can be subclassed. An abstract method is a method that is declared without an implementation.

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

What is an interface?

A

An interface is a completely abstract class which can only contain abstract methods and properties.

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

What is a C# property?

A

A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field.

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

What does a constructor do?

A

It is used to initialise and set default values for the data member of the new object from a class.

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

What is the difference between method overloading and method overriding?

A

In method overloading, methods must the have the same name and different signatures. Method overriding it’s the same name and same signature.

17
Q

How does C# support Encapsulation?

A

Properties, backing fields and methods.

18
Q

What is the difference between a constructor and other methods?

A

Constructor is used to initialise an object whereas method is used to exhibit the function of an object.

19
Q

What does the virtual keyword mean?

A

The virtual keyword is used to modify a method, property indexer, or event declaration and allow it to be overly in a derived class.

20
Q

What does the sealed keyword mean?

A

It restricts classes or methods to be inherited by a subclass

21
Q

What are the 5 solid principles?

A
Single responsibility principle
Open/Closed principle
Liskov Substitution principle 
Interface Segregation principle
Dependency Inversion principle
22
Q

What are the elements of a class?

A

Class name, type, fields, properties, methods, access modifiers(public, private, protected).

23
Q

What properties and methods does the object class have?

A

Equals(),GetHashCode(),GetType(),ToString(), ReferenceEquals().

24
Q

What is the single responsibility principle?

A

That an object/class should only have one responsibility and that it should be completely encapsulated by the class.

25
What is the open/closed principle?
An entity allows it's behaviour to be extended but never by modifying it's source code.
26
What is the Liskov Substitution principle?
That objects should be replaceable by instances of their subtypes and that without affecting the functioning of your system from a client's point of view.
27
What is the Interface Segregation principle?
Large interfaces need to be split into smaller interface that are more specific.
28
What is Dependency Inversion principle?
High level modules should not depend on low level modules rather both should depend on abstraction. Abstraction should not depend on details; rather detail should depend on abstraction.