标签:call school student public setname 打电话 print bsp 学习
public class Emp {
String name;
int age;
public void work(){
System.out.println("员工正在工作");
}
}
//维护部员工继承自员工
public class WeiHu extends Emp{
//自己的方法
public void speak(){
System.out.println("我叫"+name);
}
}
//研发部员工继承自员工
public class Yanfa extends Emp{
}
public class Test {
public static void main(String[] args) {
Yanfa yf=new Yanfa();
yf.name="小猪佩奇";
yf.age=18;
yf.work();
WeiHu wh=new WeiHu();
wh.name="乔治";
wh.age=18;
wh.work();
wh.speak();
}
}
//方法重写
public class Phone {
public void show(){
System.out.println("显示电话号码");
}
public void duanxin(){
System.out.println("发短信");
}
public void call(){
System.out.println("打电话");
}
}
public class Iphone extends Phone{
public void show(){
super.show();
System.out.println("显示头像");
System.out.println("显示姓名");
}
}
public class Test1 {
public static void main(String[] args) {
Iphone i=new Iphone();
i.show();
i.duanxin();
i.call();
}
}
//私有化 方法重写
public class School {
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 void work(){
System.out.println(name+age);
System.out.println("吃饭");
}
}
public class Student extends School{
public void work(){
super.work();
System.out.println("学习");
}
}
public class Teacher extends School{
public void work(){
super.work();
System.out.println("讲课");
}
}
public class Test1 {
public static void main(String[] args) {
Teacher t=new Teacher();
t.setName("吴丹");
t.setAge(18);
t.work();
Student s=new Student();
s.setName("赵涛");
s.setAge(18);
s.work();
}
}
public abstract class Developer {
//抽象方法
public abstract void work();
//普通方法
public void speak(){
System.out.println("研发部员工开会");
}
}
public class JavaEE extends Developer{
public void work(){
System.out.println("Hello everone");
}
}
public class Test {
public static void main(String[] args) {
JavaEE j=new JavaEE();
j.work();
j.speak();
}
}
标签:call school student public setname 打电话 print bsp 学习
原文地址:https://www.cnblogs.com/zhaotao11/p/10209239.html