M
mfunkmann
Hi there,
I was trying to pogram a class hierachy, and it worked great until I
was trying to implement GetModel, for some reasons I can't acess it in
the main program. But if I add the GetModel-function in the Auto
Object it suddenly it suddelny works, I am not sure want went wrong
there..
Thanks in advance
Mattias
class Program
{
abstract class Fahrzeug
{
protected int _raeder;
protected int Raeder
{
get { return _raeder; }
set { _raeder = value; }
}
protected int _ps;
protected int Ps
{
get { return _ps; }
set { _ps = value; }
}
public Fahrzeug(int p, int r)
{
_ps = p;
_raeder = r ;
}
public virtual void Startengine()
{
System.Console.WriteLine("Brumm Brummm");
}
}
class Auto:Fahrzeug
{
public Auto(int p, int r): base(p, r) {}
}
class Sportwagen : Auto
{
public string GetModel()
{
return ("ZX-12");
}
public Sportwagen(int p, int r) : base(p, r) { }
public override void Startengine()
{
System.Console.WriteLine("Sportwagen Start!");
}
}
interface Turbo
{
string GetModel();
}
static void Main(string[] args)
{
Auto f = new Auto(2,12);
f.Startengine();
Auto SW = new Sportwagen(2, 12);
SW.Startengine();
System.Console.WriteLine(SW.GetModel);
// error: Error 1 'ConsoleApplication4.Program.Auto' does not contain
a definition for 'GetModel' C:\Documents and Settings\Administrator\My
Documents\Visual Studio 2005\Projects
\ConsoleApplication4\ConsoleApplication4\Program.cs 81 41
ConsoleApplication4
}
}
I was trying to pogram a class hierachy, and it worked great until I
was trying to implement GetModel, for some reasons I can't acess it in
the main program. But if I add the GetModel-function in the Auto
Object it suddenly it suddelny works, I am not sure want went wrong
there..
Thanks in advance
Mattias
class Program
{
abstract class Fahrzeug
{
protected int _raeder;
protected int Raeder
{
get { return _raeder; }
set { _raeder = value; }
}
protected int _ps;
protected int Ps
{
get { return _ps; }
set { _ps = value; }
}
public Fahrzeug(int p, int r)
{
_ps = p;
_raeder = r ;
}
public virtual void Startengine()
{
System.Console.WriteLine("Brumm Brummm");
}
}
class Auto:Fahrzeug
{
public Auto(int p, int r): base(p, r) {}
}
class Sportwagen : Auto
{
public string GetModel()
{
return ("ZX-12");
}
public Sportwagen(int p, int r) : base(p, r) { }
public override void Startengine()
{
System.Console.WriteLine("Sportwagen Start!");
}
}
interface Turbo
{
string GetModel();
}
static void Main(string[] args)
{
Auto f = new Auto(2,12);
f.Startengine();
Auto SW = new Sportwagen(2, 12);
SW.Startengine();
System.Console.WriteLine(SW.GetModel);
// error: Error 1 'ConsoleApplication4.Program.Auto' does not contain
a definition for 'GetModel' C:\Documents and Settings\Administrator\My
Documents\Visual Studio 2005\Projects
\ConsoleApplication4\ConsoleApplication4\Program.cs 81 41
ConsoleApplication4
}
}