这样吧:代码如下:
class Person
{
String name;
String country;
Person(String name,String country)
{
this.name=name;
this.country=country;
}
public void sayHello()
{
System.out.println("我是"+this.name+','+"我来自"+this.country);
}
}
class Chinese extends Person
{
Chinese(String name,String country)
{
super(name,country);
}
}
class Demo
{
public static void main(String[] args)
{
Person c = new Chinese("张三","中国");
c.sayHello();
}
} |