interface Frob{
Object display();
}
class Inform implements Frob{
public Frob display() {
System.out.print("通知:");
return null;
}
}
class Car implements Frob{
public Frob display() {
System.out.print("汽车油量:");
return null;
}
}
class Ad implements Frob{
public Frob display() {
System.out.print("广告:");
return null;
}
}
public class test8_1 {
public static void main(String[] args) {
Inform T=new Inform();
T.display();
}
}
interface shape{
float size();
}
class rectangle implements shape{
int length;
int wide;
public rectangle(int x,int y){
length=x;
wide=y;
}
public float size() {
return length*wide;
}
}
class circle implements shape{
int r;//半径
public circle(int x){
r=x;
}
public float size() {
return (float) (3.14*r*r);
}
}
class column implements shape{
int r;//半径
int hight;//高
public column(int x,int y){
r=x;
hight =y;
}
public float size() {
return (float) ((float) (2*3.14*r*r)+(2*3.14*r*hight));
}
}
public class test8_2 {
public static void main(String[] args) {
shape[] S=new shape[3];
S[0]=new rectangle(1,5);
S[1]=new circle(5);
S[2]=new column(5,2);
for(int i=0;i<3;i++)
System.out.println(S[i].size());
}
}
abstract class fruit{
abstract double getWeight();
}
class Apple extends fruit{
double W;
public Apple(int w){
W=w;
}
public double getWeight() {
return W;
}
}
class Peach extends fruit{
double W;
public Peach(int w){
W=w;
}
public double getWeight() {
return W;
}
}
class Orange extends fruit{
double W;
public Orange(int w){
W=w;
}
public double getWeight() {
return W;
}
}
public class test8_3 {
public static void main(String[] args) {
fruit[] f=new fruit[3];
f[0]=new Apple(100);
f[1]=new Peach(200);
f[2]=new Orange(300);
for(int i=0;i<3;i++)
System.out.println(f[i].getClass().getSimpleName()+":"+f[i].getWeight()+"KG");
}
}