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. Spring Aop(十一)——编程式的创建Aop代理之ProxyFactory

    转发地址:https://www.iteye.com/blog/elim-2397388 编程式的创建Aop代理之ProxyFactory Spring Aop是基于代理的,ProxyFactory是 ...

  2. 利用工具破解HTTP身份验证的多种方法

    https://www.hackingarticles.in/multiple-ways-to-exploiting-http-authentication/ 1)场景 利用Apache配置HTTP验 ...

  3. golang web框架设计2:自定义路由

    继续学习谢大的Go web框架设计 HTTP路由 http路由负责将一个http的请求交到对应的函数处理(或者一个struct的方法),路由在框架中相当于一个事件处理器,而这个时间包括 用户请求的路径 ...

  4. thymeleaf如何遍历数据 each循环的使用

    首先在html开始标签中引入一个属性 xmlns:th="http://www.thymeleaf.org" 遍历数据示例 <tbody> <tr th:each ...

  5. 修改ssh登录的初始目录

    目录 修改ssh登录的初始目录 title: 修改ssh登录的初始目录 date: 2019/11/27 20:18:27 toc: true --- 修改ssh登录的初始目录 /etc/passwd ...

  6. CentOS7.1 VNC Server服务配置

    一.安装VNC相关包 yum -y install tigervnc tigervnc-server tigervnc-server-module 二.复制配置模板文件为vncserver@:1.se ...

  7. 0《STL源码剖析》简介

    STL源码剖析 ----侯捷 STL主要包括六个组件: 1.配置器:负责空间配置和管理. 2.迭代器:扮演容器和算法之前的胶合剂,所谓“泛型指针”. 3.容器:各种数据结构,如vector,list, ...

  8. rpm 包安装调试缺少依赖无法安装的方法

    今天在给龙芯中标机器安装360 10.0.2001.1 版本时 发现有依赖过不去. 因为依赖关系而调过软件包: browser360-cn-stable-10.0.2001.0-1.mips64el ...

  9. System x 服务器制作ServerGuide U盘安装Windows Server 2008 操作系统 --不格式化盘

    1.全格式化 用ServerGuide10.5 刻录成U盘 下载附件中的Rufus 3.6工具,并制作引导U盘 以管理员权限打开Rufus 3.6, 选择镜像文件 2.不格式化,仅安装C盘下载老毛桃U ...

  10. 使用jbc查询数据封装成对象的工具类

    适用于获取Connection对象的util package com.briup.myDataSource; import java.io.FileReader; import java.io.Inp ...