Hi there,
I have an oop happenig but no idea if it based up polymorphy or just inheritance.
There are two classes: ClsAuto and ClsJeep
ClsAuto is the baseclass in this case and ClsJeep derivedclass.
ClsJeep has no more than an construktor, to decide how much gears it shal has.
Within static void Main I chose those methode "Gearup" and finally it shows me ClsJeep has gotten it first gear.
Thats fine, but what is it? Polymorphy? Or just inheritance?
Polymorphy is described as the posibility to give other capabilitys to those derivedclass, (using override)
But obviously this ClsJeep has'nt override any method or property
Inheritance is described as: every property and method are usable within derivedclass as well.
Thats true in this case, but does not explain that effect.
good night albert
I have an oop happenig but no idea if it based up polymorphy or just inheritance.
There are two classes: ClsAuto and ClsJeep
ClsAuto is the baseclass in this case and ClsJeep derivedclass.
ClsJeep has no more than an construktor, to decide how much gears it shal has.
Within static void Main I chose those methode "Gearup" and finally it shows me ClsJeep has gotten it first gear.
Thats fine, but what is it? Polymorphy? Or just inheritance?
Polymorphy is described as the posibility to give other capabilitys to those derivedclass, (using override)
But obviously this ClsJeep has'nt override any method or property
Inheritance is described as: every property and method are usable within derivedclass as well.
Thats true in this case, but does not explain that effect.
good night albert
Code:
class Program
{
[COLOR=Blue]static void Main(string[] args)[/COLOR]
{
ClsAuto myCar = new ClsAuto(4);
ClsJeep myJeep = new ClsJeep(6);
myCar.GearUp();
myCar.GearUp();
myCar.GearUp();
Console.WriteLine("" + myCar.GearActual);
Console.ReadLine();
myJeep.GearUp();
Console.WriteLine("" + myJeep.GearActual);
Console.ReadLine();
}
}
[COLOR=Blue]public class ClsAuto[/COLOR]
{
private int mIntGearMax;
private int mIntGearActual;
#region "Construktor"
public ClsAuto() { } //Construktor
public ClsAuto(int IntGearMax)
{
GearMax = IntGearMax;
}
#endregion
public void GearUp() //Method
{
GearActual++;
}
#region "Propertys"
public int GearMax //Propertys
{
get { return mIntGearMax; }
set
{
if (value > 0)
{
this.mIntGearMax = value;
}
else
{
Console.WriteLine ("Gear needs to be higher than 0 ");
}
}
}
public int GearActual
{
get { return mIntGearActual; }
set
{
if (value < this.mIntGearMax)
mIntGearActual = value;
else
{ Console.WriteLine("No more than" + mIntGearActual); }
}
}
#endregion
}
[COLOR=Blue]class ClsJeep : ClsAuto[/COLOR]
{
public ClsJeep(){ }
public ClsJeep(int IntGearMax)
: base(IntGearMax) { }
}