• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/8

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

8 Cards in this Set

  • Front
  • Back
What is OOP?
Object-Oriented Programming allows groups of objects to cooperate with each other by exchanging data, messages, and logical framework to achieve a common simple or complex goal.
What are the tenents of OOP?
• Encapsulation: Hiding the details of the internal implementation. Encapsulations is also the process of grouping related data and methods into a single class.
What is inheritance?
Inheritance is the object-oriented mechanism for program organization. It allows a program to be structured following a real-world model and facilitates code reuse.
What are some key features of inheritance in C#?
C# requires single inheritance:
A class must inherit from exactly one base class.
When base class is not specified in the declaration of a class, then the class automatically inherits from System.Object.
What is the basic syntax for inheritance?
The C# syntax to inherit from a class is as follows:
class Vehicle : System.Object
{
}
In this example, we create a class that inherits explicitly from System.Object. Note that this is the default. If no inheritance is indicated, System.Object is automatically the base class. The syntax to inherit from the Vehicle class (created above) is the same:

class Car : Vehicle { }
class Boat : Vehicle { }
class Airplane : Vehicle { }
Here we create three derived classes: Car, Boat, and Airplane which extends the Vehicle class. Note that we say that each subclass is-a Vehicle.
What is encapsulation?
Member hiding is the behavior that happens when a derived class has a member with the same name or signature (in the case of a method) as the base class. For example:

class Vehicle
{
protected int fuelLevel = 100;
public int Start(){}
}

class Boat : Vehicle
{
private new float fuelLevel = 50.0f;
public new int Start(){}
}
In this example the Boat class hides two members of the Vehicle class: the variable fuelLevel and the method Start(). Be aware of the following points about hiding members:

You can hide any class member including data members, methods, events, and properties.
The data member in the derived class that hides the base data member does not need to be of the same type.
Use the new keyword in the derived class to alert the compiler that the data member is hidden. Without the new keyword, the compiler will give a warning (not an error) when hiding base class members.
Note: If you reference the hidden member in the derived object, the base class member, not the derived object member, will be referenced. For example:

Vehicle v = new Boat();
v.Start();
The call to v.Start() in this example invokes the Vehicle.Start() method, not the Boat.Start() method. Usually, this is not the behavior you want or expect.
What is polymorphism?
Any time you use the virtual keyword, you are performing polymorphism.

0verriding Members
When you override a base class member, you write code in the derived class that will be used instead of the code in the base class. To override a member:

In the base class, add the virtual keyword to the member. This allows derived classes to override the member.
In the derived class, use the override keyword to redefine the member.
For example:

class Vehicle
{
public virtual int Start(){}
}

class Boat : Vehicle
{
public override int Start(){}
}
Given this example, when you access an overridden method as follows:
Vehicle v = new Boat();
v.Start();
The call to v.Start() in this example invokes the Boat.Start() method. This is usually what we want and expect. Contrast this to the hiding example above where the same call accessed the base class member instead.

Some things to note about overriding members:

• You cannot override data members or a type (such as nested classes, delegates, etc.)
• You cannot override static members.
• Private members cannot be virtual.
• The overriding member must have the same return type and parameters as the base member.
• You may not change the access modifier when overriding a class member.
What is the difference between overriding and overloading?
In overriding, you create a new behavior for that method signature in another class or structure.

In overloading, you create a new behavior for that method name within the same class. A caveat is that, within the same class, the number of parameters, the order of parameters or both number and order must be different. The return type has nothing to do with method overloading.