day09--继承的格式和基本使用
This commit is contained in:
@@ -7,6 +7,7 @@ public static double floor(double a) :返回小于等于参数最大的整数
|
||||
public static long round(double a) :返回最接近参数的 long。(相当于四舍五入方法)
|
||||
*/
|
||||
public class MathDemo11 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
//获取绝对值
|
||||
@@ -19,4 +20,9 @@ public class MathDemo11 {
|
||||
System.out.println(Math.round(4.4));//4
|
||||
System.out.println(Math.round(4.5));//5
|
||||
}
|
||||
|
||||
public void methos() {
|
||||
System.out.println(Math.round(4.4));//4
|
||||
System.out.println(Math.round(4.5));//5
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="17" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.inmind.extends01;
|
||||
|
||||
public class Assistant extends Employee {
|
||||
|
||||
public void help(){
|
||||
System.out.println("助教在帮助学生");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.inmind.extends01;
|
||||
|
||||
public class BanZhuRen extends Employee {
|
||||
|
||||
public void manage(){
|
||||
System.out.println("班主任在管理学生");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.inmind.extends01;
|
||||
/*
|
||||
继承的格式和和基本使用
|
||||
public class Fu{
|
||||
}
|
||||
public class Zi extends Fu{
|
||||
}
|
||||
继承的特点:子类拥有父类的所有内容,除了被private和构造方法。
|
||||
继承的好处:实现多个类中相同内容的复用,子类可以实现各自的不同功能需求
|
||||
*/
|
||||
public class Demo01 {
|
||||
public static void main(String[] args) {
|
||||
//创建一个子类对象,老师对象
|
||||
Teacher t = new Teacher();
|
||||
t.name = "张三";
|
||||
t.age = 35;
|
||||
t.salary = 1.5;
|
||||
t.work();
|
||||
t.teach();
|
||||
Assistant a = new Assistant();
|
||||
a.help();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.inmind.extends01;
|
||||
|
||||
public class Employee {
|
||||
String name;
|
||||
int age;
|
||||
double salary;
|
||||
|
||||
public void work(){
|
||||
System.out.println("员工工作了");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.inmind.extends01;
|
||||
|
||||
public class Teacher extends Employee{
|
||||
//默认无参构造,所有类都有构造方法
|
||||
|
||||
public void teach(){
|
||||
System.out.println("老师在教学生学java");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user