继承
作者:互联网
方法的重写
package test1;
class ManKind{
intsex;
intsalary;
void manOrWoman()
{
if(sex==0)
System.out.println("man");
else
System.out.println("woman");
}
void employeed()
{
if(sex==0)
System.out.println("no job");
else
System.out.println("job");
}
}
class Kids extends ManKind{
intyearsOld;
void PrintAge()
{
System.out.println(yearsOld);
}
}
publicclass Test {
publicstaticvoid main(String[] args) {
Kids A=new Kids();
A.salary=1;
A.sex=1;
A.yearsOld=19;
A.employeed();
A.manOrWoman();
A.PrintAge();
}
}
package test1;
class ManKind{
intsex;
intsalary;
void manOrWoman()
{
if(sex==0)
System.out.println("man");
else
System.out.println("woman");
}
String employeed()
{
if(sex==0)
return"no job";
else
return"job";
}
}
class Kids extends ManKind{
intyearsOld;
void PrintAge()
{
System.out.println(yearsOld);
}
String employeed()
{
return"Kids should study and no job";
}
}
publicclass Test {
publicstaticvoid main(String[] args) {
Kids A=new Kids();
A.salary=1;
A.sex=1;
A.yearsOld=19;
A.employeed();
A.manOrWoman();
A.PrintAge();
System.out.println(A.employeed());
}
}
标签:Kids,继承,System,sex,println,employeed,out 来源: https://www.cnblogs.com/wjingbo/p/15036472.html