特性
例
class student
{
string name;
int age;
void study(){}
}
class worker
{
string name;
int age;
void working(){}
}
=》换成:
class Person
{
string name;
int age;
}
class student extends Person
{
void study(){}
}
class worker extends Person
{
void working(){}
}
5、this/super的区别
class fu
{
int num=4;
}
class zi extends fu
{
int num=5;
void show()
{
system.out.println(num); =5
system.out.println(this.num); =5
system.out.println(super.num);=4
}
}
class zizi extends fu
{
int num=5;
void show()
{
int num=3;
system.out.println(num); =3
system.out.println(this.num); =5
system.out.println(super.num);=4
}
}
class zizizi extends fu
{
void show()
{
system.out.println(num); =4
system.out.println(this.num); =4
system.out.println(super.num);=4
}