これは私のコードです。その中でいくつかの基本的な継承を行おうとしていますが、displayメソッドが機能していないようです。コンストラクターと関係があると思うので、すでに「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();
}
}
}