Task 1
- This first task is fairly simple, you need to research and build a simple program that uses inheritance in its structure. The program needs a Base class that contains Fields and Methods, then expand that and create Derived classes that use the Fields and Methods in the Base class to create some result. The subject of this program is open. Upload the project once complete.
Task 2
- There are several ways to use Inheritance. One of the ways is Single Inheritance, this uses a single Base Class which the program inherits throughout. This means there is a class to start. Call it class A. Another class (class B) derives from class A (the base). Yet another class (class C) derives from class B. It uses class B as its base. There is a keyword “base” when you want to refer to the prior class from within the current class. When you create a class you name the base from which the new class is derived. When you are referencing a prior class, you use the word “base”.
Your task is to complete the inheritance. The Base Class is Metals, what is the inheritance for the other classes? Read the code and complete it, look for the: ??????????, what should they be? Copy the code into a Word document, add the inheritance and upload your results.
class Metals
{
string _metalType;
public Metals(String type)
{
_metalType = type;
Console.WriteLine("Metal\t\t:" + _metalType);
}
}
class SteelCompany : ?????????? //New class - What goes here?
{
string _grade;
public SteelCompany(string grade) : ??????????("Steel") //Reference - What goes here?
{
_grade = grade;
Console.WriteLine("Grade\t\t:" + _grade);
}
}
class Automobiles : ?????????? //New class - What goes here?
{
{
string _part;
public Automobiles(string part): ??????????("Cast Iron") //Reference - What goes here?
{
{
_part = part;
Console.WriteLine("Part\t\t:" + _part);
}
public static void Main()
{
Automobiles auto = new Automobiles("Mercedes");
Console.ReadKey();
}
Task 3
- Should you use Multi-Inheritance? There are a large number of articles, websites and books fighting the cause for both sides. It might be an easier decision that you think,Multi-Inheritance in C# is not strictly possible. You would think that you could simply put "class myClass : public Grass, public Animals{}; like you can is other languages. But this is not possible in C#, so what can we do?
Your task here is to research this issue of Inheritance from multiple classes, are we stuck with just one classInheritance? Search for “Interfaces”. Write a program to allow forMulti-Inheritance of classes. How would you get around the issue ofMulti-Inheritance in C#?
Upload the program once you have completed and do not forget the discussion forum to share your ideas.