Topic:
(1) Encapsulation of a people type, with the height and weight properties, with Speakhello, Averageheight, Averageweight function.
(2) Package A class of chinapeople type is people, add chinamartial function, override Super Speakhello, Averageheight, Averageweight function.
(3) Package A class of americanpeople type is people, add americanboxing function, override Super Speakhello, Averageheight, Averageweight function.
(4) Package A class of beijingpeople type is chinapeople, add Beijingopera function, override Super Speakhello, Averageheight, Averageweight function.
(5) Use a program to execute entrance test to test the above object.
People type:
Abstract class People {
float height;
float weight;
void Speakhello () {
System.out.println ("Hello");
}
abstract void Averageheight ();
void Averageweight () {
}
}
Americanpeople type
public class Americanpeople extends people{
@Override
void Averageheight () {
//TODO auto-generated method Stub
height = 1.8f;
System.out.println ("americanpeople height =" +height);
}
void Speakhello () {
System.out.println ("Americanpeople say Hello");
}
void Averageweight () {
weight = n;
System.out.println ("americanpeople weight =" +weight);
}
People subclass, add americanboxing function, override Speakhello, Averageheight, averageweight function of super class.
void Americanboxing () {
System.out.println ("Americanpeople Boxing OK");
}
Beijingpeople type
public class Beijingpeople extends chinapeople{
//Is chinapeople subclass, new Beijingopera feature, override for Super class Speakhello, Averageheight, Averageweight function.
void Averageheight () {
//TODO auto-generated method stub
height = 1.75f;
System.out.println ("beijingpeople height =" +height);
}
void Speakhello () {
System.out.println ("Beijingpeople say Hello");
}
void Averageweight () {
weight =;
System.out.println ("beijingpeople weight =" +weight);
}
void Beijingopera () {
System.out.println ("Beijingpeople Opera best");
}
Chinapeople type
public class Chinapeople extends people{
@Override
void Averageheight () {
//TODO auto-generated method stub
height = 1.7f;
System.out.println ("chinapeople height =" +height);
}
Add Chinamartial function, override Speakhello, Averageheight, Averageweight function.
void Speakhello () {
System.out.println ("Chinapeople say Hello");
}
void Averageweight () {
weight =;
System.out.println ("chinapeople weight =" +weight);
}
void Chinamartial () {
System.out.println ("Chinapeople martial Best");
}
Test the above object
public class Test {
/**
* @param args */public
static void Main (string[] args) {
//TODO Auto-generat Ed method stub
Chinapeople CP = new Chinapeople ();
Cp.averageheight ();
Cp.averageweight ();
Cp.speakhello ();
Cp.chinamartial ();
System.out.println ();
Americanpeople AP = new Americanpeople ();
Ap.speakhello ();
Ap. Americanboxing ();
Ap.averageheight ();
Ap.averageweight ();
System.out.println ();
Beijingpeople BP = new Beijingpeople ();
Bp.speakhello ();
Bp.averageheight ();
Bp.averageweight ();
Bp. Beijingopera ();
}
Run Result: