package b;

public class Car {
public final static Car pinpai=new Car();
public static Car instance()
{
return pinpai;
}
public void drive()
{
System.out.println("请安全驾驶!");
}
}
package b;

public class Aodi extends Car {
private String price;
private String xinghao;
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getXinghao() {
return xinghao;
}
public void setXinghao(String xinghao) {
this.xinghao = xinghao;
}
public void biansu(int a)
{
if(a>0)
{
System.out.println("加速");
}
else if(a<0)
{
System.out.println("减速");
}
else
{
System.out.println("匀速前进");
} } }
package b;

public class Benchi extends Car {
private String price;
private String xinghao;
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getXinghao() {
return xinghao;
}
public void setXinghao(String xinghao) {
this.xinghao = xinghao;
}
public void biansu(int a)
{
if(a>0)
{
System.out.println("加速");
}
else if(a<0)
{
System.out.println("减速");
}
else
{
System.out.println("匀速前进");
} }
}
package b;

public class E {

    public static void main(String[] args) {
Aodi aodi=new Aodi();
aodi.setXinghao("奥迪Q7");
aodi.setPrice("110万");
System.out.println(aodi.getXinghao());
System.out.println(aodi.getPrice());
aodi.biansu(90);
aodi.drive();
Benchi benchi=new Benchi();
benchi.setXinghao("迈巴赫");
benchi.setPrice("200万");
System.out.println(benchi.getXinghao());
System.out.println(benchi.getPrice());
benchi.biansu(-90);
benchi.drive();
} }

编写一个Car类,具有final类型的属性品牌,具有功能drive; 定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速; 定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特 性。的更多相关文章

  1. 编写一个Car类,具有String类型的属性品牌,具有功能drive; 定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速; 定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特 性。

    package com.hanqi.test; public class Car { //构造一个汽车的属性 private String name; //创建getter和setter方法 publ ...

  2. 24.编写一个Car类,具有String类型的属性品牌,具有功能drive; 定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速; 定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特 性。

    package zhongqiuzuoye; public class Car { String brand; public void drive() {} } package zhongqiuzuo ...

  3. 27.编写一个Animal类,具有属性:种类;具有功能:吃、睡。定义其子类Fish 和Dog,定义主类E,在其main方法中分别创建其对象并测试对象的特性。

    ///Animal类 package d922A; public class Animal { private String kind; public String getKind() { Syste ...

  4. 在主类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 = ...

  5. 编写一个Animal类,具有属性:种类;具有功能:吃、睡。定义其子类Fish 和Dog,定义主类E,在其main方法中分别创建其对象并测试对象的特性。

    package animal; public class Animal { //成员属性 private String kind; public String getKind() { return k ...

  6. 22.编写一个类A,该类创建的对象可以调用方法showA输出小写的英文字母表。然后再编写一个A类的子类B,子类B创建的对象不仅可以调用方法showA输出小写的英文字母表,而且可以调用子类新增的方法showB输出大写的英文字母表。最后编写主类C,在主类的main方法 中测试类A与类B。

    22.编写一个类A,该类创建的对象可以调用方法showA输出小写的英文字母表.然后再编写一个A类的子类B,子类B创建的对象不仅可以调用方法showA输出小写的英文字母表,而且可以调用子类新增的方法sh ...

  7. Java连载67-深入一维数组、main方法中的args参数详解

    一.复习了一维数组,还复习了强制类型转换的注意点. package com.bjpowernode.java_learning; public class D67_1_GoDeepIntoArrays ...

  8. Java main方法中的String[] args

    -- Java 命令行参数 -- 关于其中的args以及public static / static public Java 命令行参数 前面已经看到多个使用Java数组的示例,每一个Java应用程序 ...

  9. Java:main方法前面一定要加static?在main方法中一定要调用static方法?

    今天敲代码的时候发现,出现了这样一个情况: 我在我在main方法中调用了一个函数,并且这个函数没有用static修饰,就像这样: 这样报错了!!! 我虽然学Java 的时间也不多,但这个问题也帮助我更 ...

随机推荐

  1. 夺命雷公狗---Thinkphp----3之后台搭建

    我们这里来搭建我们网站所需要用到的后台: 我们直接打开WEB目录,然后直接赋值Home文件粘贴并改名为Admin,效果如下所示: 然后修改他的控制器: 代码修改成如下所示: <?php name ...

  2. 有关git的换行符的处理问题

    签入签出时对换行符的操作: #签出时将LF转换为CRLF,签入时将CRLF转换为LF git config --global core.autocrlf true #签出时不转换,签入时转换为LF g ...

  3. java concurrency in practice读书笔记---ThreadLocal原理

    ThreadLocal这个类很强大,用处十分广泛,可以解决多线程之间共享变量问题,那么ThreadLocal的原理是什么样呢?源代码最能说明问题! public class ThreadLocal&l ...

  4. android 学习随笔二十二(小结)

    ADB进程 * adb指令 * adb install xxx.apk * adb uninstall 包名 * adb devices * adb start-server * adb kill-s ...

  5. Intel Edison

    起步: https://software.intel.com/zh-cn/node/628224 刷机: https://software.intel.com/zh-cn/flashing-firmw ...

  6. LR 常见问题收集及总结

    一:LoadRunner常见问题整理 1.LR 脚本为空的解决方法: 1.去掉ie设置中的第三方支持取消掉 2.在系统属性-高级-性能-数据执行保护中,添加loadrunner安装目录中的vugen. ...

  7. 为该目录以及子目录添加index.html

    add index.html to a directory recursively using Perl5 使用的目录,是从Perl下载的perl5.18.2的文档 Look Here #!/usr/ ...

  8. matlab读入矩阵数据

    方法: 很简单,把矩阵数据存到excel里,然后存成cvs的格式,就是把每行数据之间用‘,’分隔:行与行之间用‘\n’保存. 举例: 假设cvs为test_nnfeature.txt,后缀可以改啦,只 ...

  9. php 的 构造函数 和 析构函数

    构造函数 在C++ java里的应用及其普遍,今天好好研究了一下 php 的 构造函数 和 析构函数 构造函数 和 析构函数 构造函数 void __construct ([ mixed $args ...

  10. HDU 1827:Summer Holiday(强连通)

    http://acm.hdu.edu.cn/showproblem.php?pid=1827 思路:强连通分量缩点后找入度为0的点,然后对于属于该强连通分量的找一个最小耗费的入口. #include ...