day09-继承的格式和基本使用

This commit is contained in:
2026-01-22 12:00:12 +08:00
parent e7d434aabf
commit 9f7546ccd5
5 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
package com.inmind.extends01;
public class Assistant extends Employee{
}

View File

@@ -0,0 +1,5 @@
package com.inmind.extends01;
public class BanZhuRen extends Employee {
}

View File

@@ -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) {
//创建一个班主任对象
BanZhuRen bzr = new BanZhuRen();
bzr.age = 20;
bzr.name = "张三";
bzr.salary = 5000.0;
bzr.eat();
Teacher teacher = new Teacher();
teacher.age = 20;
teacher.name = "张三";
teacher.salary = 5000.0;
teacher.eat();
}
}

View File

@@ -0,0 +1,11 @@
package com.inmind.extends01;
public class Employee {
String name;
int age;
double salary;
public void eat(){
System.out.println("要吃饭");
}
}

View File

@@ -0,0 +1,6 @@
package com.inmind.extends01;
public class Teacher extends Employee{
}