这是我的代码。我试图在其中做一些基本的继承,但显示方法似乎不起作用。我认为它与构造函数有关,所以我已经放了一个“base(a,b,c);” 那里。:)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace School
{
public class CollegeCourse
{
public CollegeCourse(String a, int b, double c)
{
dep = a;
kors = b;
cre = c;
}
public String dep;
public int kors;
public double cre;
public double fee;
public String getDep()
{ return dep; }
public int getKors()
{ return kors; }
public double getCre()
{ return cre; }
public virtual void display()
{
fee = cre * 120;
Console.WriteLine("Dep is : {0}\n"+
" Course is : {1}\n Credit is : {2}\nFee is : {3}",
getDep(), getKors(), getCre(), fee);
}
}
public class LabCourse : CollegeCourse
{
public LabCourse(String a, int b, double c)
: base(a, b, c)
{
dep = a;
kors = b;
cre = c;
}
public override void display()
{
fee = cre * 120;
Console.WriteLine(@"Dep is : {0}\n "+
"Course is : {1}\n Credit is : {2}\nFee is : {3}",
dep, kors, cre, fee + 50);
}
}
public class UseCourse
{
public static void teste()
{
String a;
int b;
double c;
Console.WriteLine("Input Department:");
a = Console.ReadLine();
Console.WriteLine("Input Course:");
b = Int16.Parse(Console.ReadLine());
Console.WriteLine("Input Credits:");
c = Double.Parse(Console.ReadLine());
CollegeCourse aw = new CollegeCourse(a, b, c);
LabCourse oy = new LabCourse(a, b, c);
aw.display();
oy.display();
Console.ReadLine();
}
}
}