标题: interface inheritance abstract [打印本页] 作者: Ethan丶 时间: 2015-9-18 00:02 标题: interface inheritance abstract package com.itheima;
/*
* Complex Interface and Inheritance
*/
//TEST
public class Test8 {
public static void main(String[] args) {
// test Athlete
PingPanger pp = new PingPanger(); //no parameter
PingPanger pp1 = new PingPanger("Wanghao",24); // parameter
pp.setName("Lining");
pp.setAge(28);
System.out.println(pp.getName()+"--"+pp.getAge());
System.out.println(pp1.getName()+"--"+pp1.getAge());
pp.eat();
pp.sleep();
pp.study();
pp1.eat();
pp1.sleep();
pp1.study();
pp.OralEnglish();
pp1.OralEnglish();
System.out.println("--------------");
BasketBaller bb = new BasketBaller(); //no parameter
BasketBaller bb1 = new BasketBaller("Yaoming",32); // parameter
bb.setName("Kobe");
bb.setAge(35);
System.out.println(bb.getName()+"--"+bb.getAge());
System.out.println(bb1.getName()+"--"+bb1.getAge());
bb.eat();
bb.sleep();
bb.study();
bb1.eat();
bb1.sleep();
bb1.study();
bb.OralEnglish();
bb1.OralEnglish();
System.out.println("--------------");
// test Coach
}
}
// define a abstract Person
abstract class Personer {
private String name;
private int age;
public Personer(){}
public Personer(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public abstract void eat(); //abstract
public void sleep(){
System.out.println("Everyone like sleep for taking a rest");
}
}
// Athlete
abstract class Athlete extends Personer {
public Athlete(){}
public Athlete(String name,int age){
super(name,age);
}
public void study(){
System.out.println("Processing further more through their coachs");
}
}
// Coach
abstract class Coach extends Personer {
public Coach(){}
public Coach(String name,int age){
super(name,age); // extends Person
}
public void teach(){
System.out.println("Coach teach who follows his way of success");
}
}
interface English {
public abstract void OralEnglish(); //define a interface of OralEnglish
}
class PingPanger extends Athlete implements English{
public PingPanger(){}
public PingPanger(String name,int age){
super(name,age); // extends Person
}
public void eat(){
System.out.println("PP eat vegetables and rice");
}
public void study(){
System.out.println("PP learn how to shoot the ball");
}
public void OralEnglish(){
System.out.println("learning PPEnglish"); //PP study ppEnglish
}
}
class BasketBaller extends Athlete implements English{
public BasketBaller(){}
public BasketBaller(String name,int age){
super(name,age);// extends Person
}
public void eat(){
System.out.println("BB eat hamburger and buff");
}
public void study(){
System.out.println("BB learn how to movate the ball");
}
public void OralEnglish(){
System.out.println("learning BBEnglish"); //BB study ppEnglish
}
}
class PingPangCoach extends Athlete implements English{
public PingPangCoach(){}
public PingPangCoach(String name,int age){
super(name,age); // extends Person
}
public void eat(){
System.out.println("PPer eat banana and watermelon");
}
public void study(){
System.out.println("PPer learn how to teach shoot the PingPang");
}
public void OralEnglish(){
System.out.println("learning PPEnglish"); //PP study ppEnglish
}
}
class BasketBallCoach extends Athlete implements English{
public BasketBallCoach(){}
public BasketBallCoach(String name,int age){
super(name,age);// extends Person
}
public void eat(){
System.out.println("BBer eat apple and lemon");
}
public void study(){
System.out.println("BBer learn how to teach movate the basket");
}
public void OralEnglish(){
System.out.println("learning BBEnglish"); //BB study ppEnglish
}
} 作者: Ethan丶 时间: 2015-9-18 09:17