24.编写一个Car类,具有String类型的属性品牌,具有功能drive; 定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速; 定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特 性。
package zhongqiuzuoye;
public class Car {
String brand;
public void drive()
{}
}
package zhongqiuzuoye;
public class Aodi extends Car{
public double price;
public String model;
public double speed;
public Aodi(double price,String model,double speed)
{
this.price=price;
this.model=model;
this.speed=speed;
System.out.println("价格为:"+price+"\t型号为:"+model+"\t初始速度为:"+speed);
}
double setSpeed(double s)
{
speed+=s;
System.out.println("当前车速为:"+speed);
return speed;
}
}
package zhongqiuzuoye;
public class Benchi extends Car{
public double price;
public String model;
public double speed;
public Benchi(double price,String model,double speed)
{
this.price=price;
this.model=model;
this.speed=speed;
System.out.println("价格为:"+price+"\t型号为:"+model+"\t初始速度为:"+speed);
}
double setSpeed(double s)
{
speed+=s;
System.out.println("当前车速为:"+speed);
return speed;
}
}
package zhongqiuzuoye;
public class E {
public static void main(String[] args) {
Aodi a4=new Aodi(300000,"A4",40);
a4.setSpeed(-10);
Benchi e200=new Benchi(500000,"e200",50);
e200.setSpeed(50);
}
}

24.编写一个Car类,具有String类型的属性品牌,具有功能drive; 定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速; 定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特 性。的更多相关文章
- 编写一个Car类,具有String类型的属性品牌,具有功能drive; 定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速; 定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特 性。
package com.hanqi.test; public class Car { //构造一个汽车的属性 private String name; //创建getter和setter方法 publ ...
- 编写一个Car类,具有final类型的属性品牌,具有功能drive; 定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速; 定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特 性。
package b; public class Car { public final static Car pinpai=new Car(); public static Car instance() ...
- 27.编写一个Animal类,具有属性:种类;具有功能:吃、睡。定义其子类Fish 和Dog,定义主类E,在其main方法中分别创建其对象并测试对象的特性。
///Animal类 package d922A; public class Animal { private String kind; public String getKind() { Syste ...
- 在主类E的main方法中,创建类B 的对象并赋给父类A的对象a,使用上转型对象a来测试上转型对象的一些特性。
public class A { private int a=1; public int getA() { return a; } public void setA(int a) { this.a = ...
- 编写一个Animal类,具有属性:种类;具有功能:吃、睡。定义其子类Fish 和Dog,定义主类E,在其main方法中分别创建其对象并测试对象的特性。
package animal; public class Animal { //成员属性 private String kind; public String getKind() { return k ...
- 22.编写一个类A,该类创建的对象可以调用方法showA输出小写的英文字母表。然后再编写一个A类的子类B,子类B创建的对象不仅可以调用方法showA输出小写的英文字母表,而且可以调用子类新增的方法showB输出大写的英文字母表。最后编写主类C,在主类的main方法 中测试类A与类B。
22.编写一个类A,该类创建的对象可以调用方法showA输出小写的英文字母表.然后再编写一个A类的子类B,子类B创建的对象不仅可以调用方法showA输出小写的英文字母表,而且可以调用子类新增的方法sh ...
- Java main方法中的String[] args
-- Java 命令行参数 -- 关于其中的args以及public static / static public Java 命令行参数 前面已经看到多个使用Java数组的示例,每一个Java应用程序 ...
- Java连载67-深入一维数组、main方法中的args参数详解
一.复习了一维数组,还复习了强制类型转换的注意点. package com.bjpowernode.java_learning; public class D67_1_GoDeepIntoArrays ...
- Spring 依赖注入,在Main方法中取得Spring控制的实例
Spring依赖注入机制,在Main方法中通过读取配置文件,获取Spring注入的bean实例.这种应用在实训的时候,老师曾经说过这种方法,而且学Spring入门的时候都会先学会使用如何在普通的jav ...
随机推荐
- Alpha、Beta、RC、GA版本的区别 ZT
http://www.blogjava.net/RomulusW/archive/2008/05/04/197985.html Alpha:是内部测试版,一般不向外部发布,会有很多Bug.一般只有测试 ...
- C#与Swift异步操作的差异
作为一个从C#转到Swift的小菜鸡...最近做一个简单的请求API解析Json数据的小程序上碰到一堆小问题.尤其是在异步请求的时候,用惯了C#的async/await写法,在写Swift的时候也按着 ...
- 使用ajax预加载图片
使用Ajax 上面所给出的方法似乎不够酷,那现在来看一个使用Ajax实现图片预加载的方法.该方法利用DOM,不仅仅预加载图片,还会预加载CSS.JavaScript等相关的东西.使用Ajax,比直接使 ...
- Strong name signature not valid for this assembly Microsoft.mshtml.dll
Strong name signature not valid for this assembly Microsoft.mshtml.dll http://social.msdn.microsoft ...
- Codeforces 13C(DP)
题意:给出一个数列长度小于5000,每次操作将数列中的数加1或减1,问最少需要多少步操作可以得到一个不降序列: 分析:可知最少的次数,一定是由原来的数据构成的(据说可以用反证法证),即有原来的数组成的 ...
- Linux终端杀手、程序员利器-Tmux
Send article as PDF SA.Coder.经常远程.还在开一堆终端?试试 Tmux 吧,一个窗口就搞定. 目录 0.0.0.1 Tmux ? Tmux 是一个终端复用 ...
- 平滑处理Smooth之图像预处理算法-OpenCV应用学习笔记三
大清早的我们就来做一个简单有趣的图像处理算法实现,作为对图像处理算法学习的开端吧.之所以有趣就在于笔者把算法处理的各个方式的处理效果拿出来做了对比,给你看到原图和各种处理后的图像你是否能够知道那幅图对 ...
- kali基本设置
一.更换比较快的软件源 修改sources.list文件(su): leafpad /etc/apt/sources.list #debain源 deb http://mirrors.163.com/ ...
- cocoapods安装以及使用,安装过程中ruby版本过低
cocoapods安装以及使用,安装过程中ruby版本过低 字数473 阅读103 评论1 喜欢2 1.打开终端 2.移除现有 Ruby 默认源 $ gem sources --remove http ...
- angularjs http 请求拦截器
/** * Created by oy on 2016/11/29. */ (function() { 'use strict'; // 创建angular模块 angular .module('ap ...