这道题错在哪里了,不难
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/11 07:02:14
这道题错在哪里了,不难
using System;
using System.Collections.Generic;
using System.Text;
namespace _
{
class Program
{
static void Main()
{
class1 c1 = new class1();
c1.str2 = "shanghai";
class2 c = new class2();
c.sum();
}
}
class class1
{
protected string str1;
public string str2
{
get
{
return str1;
}
set
{
str1 = str2;
}
}
}
class class2:class1
{
public void sum()
{
string str3 = base.str1;
Console.WriteLine("{0}",str3);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace _
{
class Program
{
static void Main()
{
class1 c1 = new class1();
c1.str2 = "shanghai";
class2 c = new class2();
c.sum();
}
}
class class1
{
protected string str1;
public string str2
{
get
{
return str1;
}
set
{
str1 = str2;
}
}
}
class class2:class1
{
public void sum()
{
string str3 = base.str1;
Console.WriteLine("{0}",str3);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
class Program
{
static void Main()
{
class2 c = new class2();
c.str2 = "shanghai";
c.sum();
}
}
class class1
{
protected string str1;
public string str2
{
get
{
return str1;
}
set
{
str1 = value;
}
}
}
class class2 : class1
{
public void sum()
{
string str3 = base.str1;
Console.WriteLine("{0}", str3);
}
}
这样改就行了,另外你对派生和继承理解得不清楚,自己摸索吧……
using System.Collections.Generic;
using System.Text;
class Program
{
static void Main()
{
class2 c = new class2();
c.str2 = "shanghai";
c.sum();
}
}
class class1
{
protected string str1;
public string str2
{
get
{
return str1;
}
set
{
str1 = value;
}
}
}
class class2 : class1
{
public void sum()
{
string str3 = base.str1;
Console.WriteLine("{0}", str3);
}
}
这样改就行了,另外你对派生和继承理解得不清楚,自己摸索吧……