java--面向对象之继承2
来源:互联网 发布:lol末日人工智能 编辑:程序博客网 时间:2024/05/01 11:14
Auto:
package JC1;
public class Auto {
private String wheel;
private String color;
private int weight;
private double speed;
public Auto(String wheel, String color, int weight, double speed) {
this.wheel = wheel;
this.color = color;
this.weight = weight;
this.speed = speed;
}
public void speedUp(){
this.speed+=10;
System.out.println("白色的"+this.color+",重量为"+this.weight+"kg"+",速度为"+this.speed+"km/h行驶!");
}
public void speedDown(){
if(this.speed-10>0){
this.speed-=10;
System.out.println("白色的"+this.color+",重量为"+this.weight+"kg"+",速度为"+this.speed+"km/h减速行驶!");
}
}
public void stop(){
this.speed=0;
System.out.println("车已停止!"+this.speed+"km/h");
}
public String getWheel() {
return wheel;
}
public String getColor() {
return color;
}
public int getWeight() {
return weight;
}
public double getSpeed() {
return speed;
}
}
Car:
package JC1;
public class Car extends Auto {
private String aircondition;
private String CD;
public Car(String wheel, String color, int weight, double speed,
String aircondition, String cD) {
super(wheel, color, weight, speed);
this.aircondition = aircondition;
CD = cD;
}
//重写
public void speedUp(){
System.out.println("白色的"+super.getColor()+",重量为"+super.getWeight()+"kg"+",速度为"+super.getSpeed()+"km/h行驶!");
}
public void speedDown(){
System.out.println("白色的"+super.getColor()+",重量为"+super.getWeight()+"kg"+",速度为"+super.getSpeed()+"km/h减速行驶!");
}
}
Test:
package JC1;
import org.junit.Test;
public class jTest {
@Test
public void test1(){
Auto auto=new Auto("4", "black", 50000, 40);
Car car=new Car("4","white",52000,65, "美的", "eason");
//System.out.println(auto.getSpeed());
auto.speedUp();
auto.speedUp();
auto.speedUp();
auto.speedDown();
auto.speedDown();
auto.speedDown();
auto.speedDown();
auto.speedDown();
auto.speedDown();
auto.speedDown();
auto.stop();
}
}
package JC1;
public class Auto {
private String wheel;
private String color;
private int weight;
private double speed;
public Auto(String wheel, String color, int weight, double speed) {
this.wheel = wheel;
this.color = color;
this.weight = weight;
this.speed = speed;
}
public void speedUp(){
this.speed+=10;
System.out.println("白色的"+this.color+",重量为"+this.weight+"kg"+",速度为"+this.speed+"km/h行驶!");
}
public void speedDown(){
if(this.speed-10>0){
this.speed-=10;
System.out.println("白色的"+this.color+",重量为"+this.weight+"kg"+",速度为"+this.speed+"km/h减速行驶!");
}
}
public void stop(){
this.speed=0;
System.out.println("车已停止!"+this.speed+"km/h");
}
public String getWheel() {
return wheel;
}
public String getColor() {
return color;
}
public int getWeight() {
return weight;
}
public double getSpeed() {
return speed;
}
}
Car:
package JC1;
public class Car extends Auto {
private String aircondition;
private String CD;
public Car(String wheel, String color, int weight, double speed,
String aircondition, String cD) {
super(wheel, color, weight, speed);
this.aircondition = aircondition;
CD = cD;
}
//重写
public void speedUp(){
System.out.println("白色的"+super.getColor()+",重量为"+super.getWeight()+"kg"+",速度为"+super.getSpeed()+"km/h行驶!");
}
public void speedDown(){
System.out.println("白色的"+super.getColor()+",重量为"+super.getWeight()+"kg"+",速度为"+super.getSpeed()+"km/h减速行驶!");
}
}
Test:
package JC1;
import org.junit.Test;
public class jTest {
@Test
public void test1(){
Auto auto=new Auto("4", "black", 50000, 40);
Car car=new Car("4","white",52000,65, "美的", "eason");
//System.out.println(auto.getSpeed());
auto.speedUp();
auto.speedUp();
auto.speedUp();
auto.speedDown();
auto.speedDown();
auto.speedDown();
auto.speedDown();
auto.speedDown();
auto.speedDown();
auto.speedDown();
auto.stop();
}
}
阅读全文
0 0
- java--面向对象之继承2
- JAVA-面向对象之继承
- Java面向对象之继承
- java面向对象之继承
- Java面向对象之继承
- Java面向对象之继承
- Java面向对象之继承
- Java面向对象之继承
- java面向对象之继承
- JAVA面向对象之继承
- java面向对象之继承
- Java 面向对象之 继承
- Java面向对象之继承
- Java面向对象之继承
- Java面向对象之继承
- Java 面向 对象之封装 、多态、继承 (2)
- java面向对象思想之继承、多态
- 黑马程序员-JAVA面向对象之继承
- 对于随机森林的通俗理解
- Linux第一课1.1-1.5
- IDEA spring-boot jpa jsp 框架搭建(三)
- CSS3实现文字流光渐变特效
- 我们为什么要使用Spring Cloud?
- java--面向对象之继承2
- 【AI架构】第四范式发布“先知”3.0,助力企业打造AI核心
- 【数字经济】概念、技术、实践:中国 500强泰康集团背后的数据驱动
- Centos7下安装11gR2(Error in invoking target 'agent nmhs' of makefile解决方式)
- 九九乘法表
- html5之sse服务器发送事件EventSource介绍
- IntelliJ IDEA 激活
- 【智能商务】饿了么张浩:我们在大数据及AI领域的实践
- 【智能商务】诸葛io于晓松:数字化营销解决方案&案例