OOP Flashcards

(17 cards)

1
Q

What means encasulaption?

A

It means that a set of related properties and methods are treated as a single object/instance/unit. This single unit it’s called Class.

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

What’s inheritance ?

A

Create a class based on another class. Let’s say we have a class A, and we created a class B, which it’s based on class A. So that means class B it’s a sub class of A (Class A it’s parent, Class B it’s his child).

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

What is polymorphism?

A

It means that two or more class can have the same method but it can implemented differently each other.

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

How I can declare a class in C#?

A

class MyClass{ … }

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

Does C# allow multi inheritance?

A

No, it doesn’t. C# just allows to inherit from one base class.

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

What’s a property in a class?

A

It’s a feature that defines the class. For example, we have a class called Person. One of Person’s properties is Age.

class Person
{
    public int age {get; set;}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s a method?

A

It’s a operation or action that can perform the class. For example:

class Person
{
     public void sayHello(){
          Console.WriteLine("Hello!");
     }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What means overload a method?

A

It means the same method can have different signature. A method signature it’s the type of ouput and the type of parameters which receives. For example, the method string getName(Person person) have this signature: returns a String, and accepts a Person object as input. So overload it’s have the same method name but with distinct signatures. For example:

void sayHello(){ /*implementation*/}
void sayHello(string name) { /*implementation*/}

Both methods have the same name but distinct signatures.

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

What’s a constructor?

A

It’s a method which initializes the properties of a class. A construct can be overloaded. For example:

class Person {
      string name;
      public Person(){
             name = "Alfonso";
      }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What’s a nested class and how it can be instantiated?

A

A nested class it’s a class which it’s inside another class. For example:

Class Parent{
     /*fields and properties*/
     Class Son{
          /*fields and properties*/
     }
}

To instantiate the child class, just use the Parent (Container) class after dot operator and the Child (Nested) class:

Parent.Son sonSubclass = new Parent.Son();

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

What’s the difference between an assembly and a namespace?

A

A namespace contain one or more class. Whereas an assembly contain one or more namespace.

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

What are the access modifiers in c#?

A

public: the type or member can be accessed by any other code in the same assembly or another assembly which references the main assembly.
private: the type or member can be accesed by code in the same class.
protected: the type or member can be accesed by code in the same class or derived class.
internal: the type or member can be accesed by any code in the same assembly.
protected internal: the type or member can be accesed by any code in the same assembly, but by any derived class in another assembly.

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

What’s a static class?

A

A static member of the class is a property, procedure, or field that is shared by all instances of a class. All members of a static class needs to be also static, it cannot access to non static members. A static class cannot be instantiated.

For example:

static class Person{
        static int age = 3;

}

To access to a member of the Person class, just access it with the dot operator:

var edadPersona = Person.age; /there’s not instantiation/

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

How I can inherit in C#?

A

Let’s say we have an Animal class, which it’s going to be our base class. And we want a child class from the Animal class (a subclass), and it’ll be called Dog. So what we need to do in C# is:

class Animal {
    /*implementation*/
}
class Dog: Animal {
     /*Dog class implementation*/
}

Now Dog has all properties and methods from Animal class.

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

How I can declare a class for not being inherited?

A

Using the keyword “sealed” while it’s being declared. For example:

sealed class Car{ /implementation/}

The next code will be raise an error because it cannot inherit from Car class:

class Corolla: Car {/implementation/}

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

How I can declare a class just for being inherited and not instantiated?

A

Using the keyword “asbract” while it’s being declared. For example:

abstract class Car{ /implementation/}

class Corolla: Car {/implementation/}

17
Q

What’s an interface?

A

It’s like a class: has properties, methods and so on. But the methods are not implemented, just declared. A class can “inherit” from an interface but it needs to implement all his methods. An interface it’s like a contract.

For example:

interface ICar{
       void start();
}
Camry:  ICar{
     void start(){
           /*Camry class start() method implementation*/
     }
}
Civic:  ICar{
     void start(){
           /*Civic class start() method implementation*/
     }
}