王宝康 发表于 2012-7-18 21:35
父类的构造方法不能被子类继承,你的demo类继承自Thread类,你在new一个demo类型的实例的时候,会先调用父 ... - class GetTest
- {
- public static void main(String[] args)
- {
- ZiGetSet zgs = new ZiGetSet("lisi");
- String M = zgs.getName();
- System.out.println(M);
- }
- }
- class FuGetSet
- {
- private String name = "yi";
- FuGetSet(){}
- public void FuGetSet(String name)
- {
- this.name = name;
- }
- public String getName()
- {
- return name;
- }
- public void setName()
- {
- this.name = name;
- }
- }
- class ZiGetSet extends FuGetSet
- {
- private String name;
- private String sex;
- ZiGetSet(){}
- ZiGetSet(String name)
- {
- this.name = name;
- }
- void ZiGetSet(String name,String sex)
- {
- this.name = name;
- this.sex = sex;
- }
- public String getName()
- {
- return name;
- }
- public void setName(String name)
- {
- this.name = name;
- }
- public String getSex()
- {
- return sex;
- }
- public void setSex()
- {
- this.sex = sex;
- }
- }
复制代码 为何这个就能改呢? |