java语言代码翻译器(java语言代码大全)
大家好,小秋来为大家解答以上的问题。java语言代码翻译器,java语言代码大全这个很多人还不知道,现在让我们一起来看看吧!
1、代码如下/** * Author: zhyx * Date:2017/11/30 * Time:8:56 */public abstract class Contailner { double r; abstract double volume();}/** * Author: zhyx * Date:2017/11/30 * Time:8:57 */public class Cube extends Contailner { public Cube(double r) { this.r=r; } @Override double volume() { return r*r*r; }}/** * Author: zhyx * Date:2017/11/30 * Time:9:01 */public class Sphere extends Contailner { public Sphere(double r) { this.r=r; } @Override double volume() { return 4/3*Math.PI*r*r*r; }}/** * Author: zhyx * Date:2017/11/30 * Time:9:02 */public class Tiji { public static void main(String[] args) { Cube cube=new Cube(4); System.out.println("立方体体积为:"+cube.volume()); Sphere sphere= new Sphere(4); System.out.println("球体体积为:"+sphere.volume()); }}为了100分//抽象类public abstract class Container {protected double r;public double getR() {return r;}public void setR(double r) {this.r = r;}abstract double volume();}//立方体public class Cube extends Container{double volume() {return Math.pow(r, 3);}}//球体public class Sphere extends Container{double volume() {return Math.PI * Math.pow(r, 3) * 4 / 3;}}//Tijipublic class Tiji {public static void main(String[] args) {Cube cube = new Cube();cube.setR(4);System.out.println("立方体体积" + cube.volume());Sphere sphere = new Sphere();sphere.setR(3);System.out.println("球体体积:" + sphere.volume());}}。
本文到此分享完毕,希望对大家有所帮助。
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时候联系我们修改或删除,多谢。