1  本题水题,就是想让你理解继承的含义

 public class Animaal {
public double weight;
public void eat(){
}
}
 public class Bird extends Animaal {
public int numberOfFins;
public void fly(){} }
 public class Dog extends Animaal {
public int numberOflegs;
public void walk(){} }
 public class Fish extends Animaal{
public int numberOfFins;
public void swim(){} }

2  本题主要考类的继承和方法的重写,方法的重写关键字@Override

 public class Circle {
public int radius;
public double getArea(){
return Math.PI*radius*radius;
}
}
 public class Cylinder extends Circle {
public double height; public Cylinder() {
} public Cylinder(double height) {
this.height = height;
}
public Cylinder(int radius,double height){
this.radius=radius;
this.height=height;
}
// 体积
public double getVolume(){
return Math.PI*radius*radius*height;
}
// 覆盖Circle 里面的getArea函数求圆柱的体积
@Override
public double getArea(){
return Math.PI*radius*radius*2+2*Math.PI*radius*height;
}
}
 import java.util.Scanner;

 public class ch08 {
public static void main(String[] args) { Scanner input = new Scanner(System.in);
System.out.println("请输入圆柱的半径、高");
Cylinder cylinder = new Cylinder(input.nextInt(),input.nextDouble());
System.out.println("圆柱的体积为:"+cylinder.getVolume());
System.out.println("圆柱的面积为:"+cylinder.getArea());
}
}

3  本题水题,考的方法和上面两题类似,注意题目要求即可

 public class Auto {
public double speed;
// 启动的方法
public void start(){
System.out.println("插上钥匙、系上安全带、一脚把离合踩到底、挂上一档、打左转向、缓慢抬脚、汽车平稳启动");
}
// 加速的方法
public void speedUp(){
System.out.println("脚慢踩油门、松开油门、踩离合到底、换挡、加速完成");
}
// 停止的方法
public void stop(){
System.out.println("慢踩刹车、达到额定速度、松开刹车、踩离合、换挡、持续到速度为0");
}
}
 public class Bus extends Auto {
public int passenger;
public Bus(int passenger){this.passenger=passenger;}
// 上车
public int gotOn(){ return ++passenger;
}
// 下车
public int gotOff(){return --passenger;}
}
 import java.util.Scanner;

 public class ch09 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入开始车上的人数");
Bus bus = new Bus(input.nextInt());
System.out.println("旅客上车");
System.out.println(bus.gotOn());
bus.start();
bus.speedUp();
System.out.println("旅客上下车");
System.out.println(bus.gotOff());
bus.stop();
}
}

4  本题主要考继承和抽象方法,关键字@Override

 

 public class Shape {
public int radius;
public int l;
public double getPrimeter(){
return 0;
}
public double getArea(){return 0;}
}
 public class Square extends Shape {
public Square() {
} public Square(int radius){this.radius=radius;}
@Override
public double getPrimeter(){
return 4*radius;
}
@Override
public double getArea(){
return radius*radius;
} }
 public class ch10 {
public static void main(String[] args) {
Square square = new Square(10);
System.out.println("正方形的周长为:"+square.getPrimeter());
System.out.println("正方形的面积为:"+square.getArea());
}
}

5  本题主要考方法的覆盖,构造方法的重写

 public class Rectangle {
public double length,width; public Rectangle(double length, double width) {
this.length=length;
this.width=width;
}
}
 public class Cuboid extends Rectangle{
public double height; public Cuboid(double length, double width, double height) {
super(length, width);
this.height = height;
} public double volume(){
return length*width*height;
}
}
 public class ch11 {
public static void main(String[] args) {
System.out.println("长方体的长、宽、高分别为10、5、2!");
Cuboid cuboid = new Cuboid(10,5,2);
System.out.println("长方体的体积为:"+cuboid.volume());
}
}

JAVA语言程序设计课后习题----第七单元解析(仅供参考)的更多相关文章

  1. JAVA语言程序设计课后习题----第八单元解析(仅供参考)

    1 本题主要考的是方法的克隆,与c++里面的拷贝有点相似,具体看书本p147 import java.util.Objects; public class Square implements Clon ...

  2. JAVA语言程序设计课后习题----第六单元解析(仅供参考)

    1 本题就是基本函数的用法 import java.util.Scanner; public class Poone { public static void main(String[] args) ...

  3. JAVA语言程序设计课后习题----第五单元解析(仅供参考)

    1 本题是水题,题目要求你求最大值.最小值,建议你用Arrays.sort函数进行排序,最大值.最小值就可以确定了 import java.util.Arrays; import java.util. ...

  4. JAVA语言程序设计课后习题----第四单元解析(仅供参考)

    1 本题水题,主要理解题目的意思即可,访问方法和修改方法可以通过快捷方式alt+insert选中你需要的成员变量即可 public class Person { public String name; ...

  5. JAVA语言程序设计课后习题----第三单元解析(仅供参考)

    1 本题水题,记住要知道输入格式即可 import java.util.Scanner; public class test { public static void main(String[] ar ...

  6. JAVA语言程序设计课后习题----第二单元解析(仅供参考)

    1 注意不同类型转换 import java.util.Scanner; public class Ch02 { public static void main(String[] args) { Sc ...

  7. JAVA语言程序设计课后习题----第一单元解析(仅供参考)

    1 本题是水题,基本的输出语句 public class test { public static void main(String[] args) { // 相邻的两个 "" 要 ...

  8. Java语言程序设计(基础篇) 第七章 一维数组

    第七章 一维数组 7.2 数组的基础知识 1.一旦数组被创建,它的大小是固定的.使用一个数组引用变量,通过下标来访问数组中的元素. 2.数组是用来存储数据的集合,但是,通常我们会发现把数组看作一个存储 ...

  9. Java语言程序设计-助教篇

    1. 给第一次上课(软件工程)的老师与助教 现代软件工程讲义 0 课程概述 给学生:看里面的第0个作业要求 2. 助教心得 美国视界(1):第一流的本科课堂该是什么样?(看里面的助教部分) 助教工作看 ...

随机推荐

  1. 解决 Windows启动时要求验证

    KB971033 微软检测盗版jar SLMGR -REARM 出现Window启动时要求验证版本, 在cmd窗口输入命令重新配置 重新启动即可 出现错误:解决办法 开始→设置,打开控制面板的“添加和 ...

  2. python多线程使用场景

    python多线程使用场景 如果程序时cpu密集型的,使用python的多线程是无法提升效率的,如果程序时IO密集型的,使用python多线程可以提高程序的整体效率 CPU密集型(CPU-bound) ...

  3. ubuntu默认root密码问题,第一次使用ubuntu需要设置root密码

    http://www.voidcn.com/article/p-yvnoogkc-ng.html 新接触ubuntu(baseondebian)的人,大多会因为安装中没有提示root密码而不太清楚为什 ...

  4. k8s install kubeadm网络原因访问不了谷哥and gpg: no valid OpenPGP data found. 解决办法

    gpg: no valid OpenPGP data found. 解决办法 待做.................................... 卡助在这curl -s https://pa ...

  5. iOS开发需要安装的工作软件

    1 源代码管理工具 SVN:SVN可以使用的客户端软件有Cornerstone,SmartSVN,svnX,乌龟SVN,莲花版svn等 或者git(sourcetree) 2 有道词典 3 Foxma ...

  6. 虚拟机中CentOS 7 x64图形化界面的安装

    VMware的初始设置如下: 图1 待虚拟机读取完iso,出现此界面 图2 我们主要是安装图形化界面的系统,所以在软件选择栏下如图选择: 图3 设置root密码,创建用户,等候安装完成: 图4 安装完 ...

  7. TensorFlow.ZC尝试

    1.资料: https://github.com/protocolbuffers/protobuf/releases https://pythonprogramming.net/introductio ...

  8. layui layer.open弹出框获取不了 input框的值

    layer.open({ title:'添加管理员', type: 1, content: $('.add_html').html(), btn:['添加', '取消'], btnAlign:'c', ...

  9. 洛谷 题解 P1353 【[USACO08JAN]跑步Running】

    动态规划 状态 dp[i][j]表示第i分钟疲劳值为j的最大值 初始 全部都为一个最小值"0" 转移 考虑休息和走 如果当前疲劳值比时间要大,显然不可能出现这种情况 如果比时间小 ...

  10. IDEA 启动项目 很慢,总会到某个点进行延迟卡顿。

    最开始的我解决的方式 clean 项目 忙完后,闲暇时间想起这个问题,然后进行 面向百度,发现了问题所在 参考文档:https://www.cnblogs.com/zhangzhonghui/p/11 ...