/*继承与抽象类*/ package com.baidu.www; abstract class Person { private String name; private int 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 Person(String name, int age) { this.name = name; this.age = age; } public Person() { super(); } @Override public String toString() { return "Person [name=" + name + ", age=" + age + "]"; } public abstract String speak(); } class ZiXia extends Person{ private float score; public ZiXia(String name, int age, float score) { super(name, age); this.setScore(score); } @Override public String speak() { return "紫霞信息:"+super.getName()+" "+super.getAge()+"岁 "+this.score+"人气"; } public float getScore() { return score; } public void setScore(float score) { this.score = score; } } class ZhiZunBao extends Person { private float salary; public ZhiZunBao(String name, int age, float salary) { super(name, age); this.setSalary(salary); } @Override public String speak() { return "至尊宝信息:"+super.getName()+" "+super.getAge()+"岁 "+this.salary+"人气"; } public float getSalary() { return salary; } public void setSalary(float salary) { this.salary = salary; } } public class GM { public static void main(String[] args) { Person ZiXia=new ZiXia("仙子",19,10); Person ZhiZunBao=new ZhiZunBao("人",18, 10); print(ZiXia.speak()); print(ZhiZunBao.speak()); } private static void print(String speak) { System.out.println(speak); } }