1.
public class lianxi04 {
public static void main(String[] args) {
c cc = new c();
System.out.println(cc.sk());
System.out.println(cc.aa());
}
}
class a{
int i = 0;
}
class b extends a{
int i = 1;
int aa(){
return super.i;
}
}
class c extends b{
int i = 2;
int sk(){
return i;
}
}
2.
public class lianxi07 {
public static void main(String[] args) {
// Person ps = new Person("dcd",19,"dewdwe");
// System.out.println(ps.getName());
Teacher tc = new Teacher("zhangsan",18,"vj",381);
tc.setName("sdckdl");
System.out.println(tc.getName());
}
}
class Person{
private String name;
private int age;
private String address;
Person(){
}
Person(String name ,int age){
this.name = name;
this.age = age;
}
Person(String name ,int age,String address){
this(name,age);
this.address = address;
}
public void setName(String name){
this.name = name;
}
public void setAge(int age){
this.age = age;
}
public void setAdsress(String address){
this.address = address;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
public String getAddress(){
return address;
}
}
class Teacher extends Person{
private int salary;
Teacher(String name,int age,String address,int salary){
super(name,age,address);
this.salary = salary;
}
public void setsalary(int salary){
this.salary = salary;
}
public int getsalary(){
return salary;
}
}
1.中的b类被c类继承,aa方法被c的对象调用返回的是b中的值,而2中person中的getname方法被student
的对象调用返回的却是student类的值,为什么? |
|