day09-继承的格式和基本使用
This commit is contained in:
26
day09/src/com/inmind/extends01/Demo01.java
Normal file
26
day09/src/com/inmind/extends01/Demo01.java
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user