day09-继承的格式和基本使用
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.inmind.extends01;
|
||||
|
||||
public class Assissant extends Employee {
|
||||
|
||||
public void help(){
|
||||
System.out.println("助教在帮助学生");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.inmind.extends01;
|
||||
|
||||
public class Banzhuren extends Employee{
|
||||
public void guanxin(){
|
||||
System.out.println(name+"关心学生心理健康");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.inmind.extends01;
|
||||
/*
|
||||
继承的格式和和基本使用
|
||||
public class Fu{
|
||||
}
|
||||
public class Zi extends Fu{
|
||||
}
|
||||
继承的特点:子类拥有父类的所有内容,除了被private和构造方法。
|
||||
继承的好处:实现多个类中相同内容的复用,子类可以实现各自的不同功能需求
|
||||
*/
|
||||
public class Demo01 {
|
||||
public static void main(String[] args) {
|
||||
//创建一个老师对象
|
||||
Teacher teacher = new Teacher();
|
||||
teacher.name = "张三";
|
||||
teacher.age = 38;
|
||||
teacher.salary = 15000;
|
||||
teacher.teach();
|
||||
//来一个班主任
|
||||
Banzhuren banzhuren = new Banzhuren();
|
||||
banzhuren.name = "王五";
|
||||
banzhuren.age = 28;
|
||||
banzhuren.salary = 10000;
|
||||
banzhuren.guanxin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.inmind.extends01;
|
||||
|
||||
public class Employee {
|
||||
String name;
|
||||
int age;
|
||||
double salary;
|
||||
double score;
|
||||
|
||||
public void work(){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.inmind.extends01;
|
||||
|
||||
public class Teacher extends Employee {
|
||||
|
||||
public void teach(){
|
||||
System.out.println(name+"老师正在讲课...");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user