java台球代码大全 桌球代码

用java继承,多态与接口

题目有关回答如下,供参考:

成都创新互联公司专注于企业全网整合营销推广、网站重做改版、平度网站定制设计、自适应品牌网站建设、H5高端网站建设商城网站定制开发、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为平度等各大城市提供网站开发制作服务。

4、this:当前对象的引用

super:当前对象的超(父)类对象的一个引用

5、继承是面向对象最显著的一个特性。

继承的意义:继承是从已有的类中派生出新的类,新的类能吸收已有类的数据属性和行为,并能扩展新的能力。

定义继承:使用关键字 extends 来实现继承

6、多态(Polymorphism)按字面的意思就是“多种状态”,也是面向对象的一个特性。

允许将子类类型的引用赋值给父类类型的引用。

7、代码如下:

/**

* 父类(图形)

* @author qd

*

*/

abstract class Figure {

double area;

}

/**

* 求面积的接口

* @author qd

*

*/

interface Area {

public void getArea();

}

/**

* 三角形

* @author qd

*

*/

class Triangle extends Figure implements Area {

// 底

double bottom;

// 高

double high;

public Triangle(double bottom, double high) {

super();

this.bottom = bottom;

this.high = high;

}

@Override

public void getArea() {

area = bottom * high * 0.5;

System.out.println("三角形面积是:" + area);

}

}

/**

* 正方形

* @author qd

*

*/

class Square extends Figure implements Area {

// 边长

double length;

public Square(double length) {

super();

this.length = length;

}

@Override

public void getArea() {

area = length * length;

System.out.println("正方形面积是:" + area);

}

}

/**

* 圆

* @author qd

*

*/

class Circular extends Figure implements Area {

// 半径

double radius;

public Circular(double radius) {

super();

this.radius = radius;

}

@Override

public void getArea() {

area = Math.PI * radius * radius;

System.out.println("圆面积是:" + area);

}

}

public class Test {

public static void main(String[] args) {

// 三角形对象

Area triangle = new Triangle(3, 4);

triangle.getArea();

// 正方形对象

Area square = new Square(4);

square.getArea();

// 圆对象

Area circular = new Circular(2);

circular.getArea();

}

}

8、代码如下:

/**

* 球类

* @author qd

*

*/

class Ball {

// 私有成员变量半径

private double r;

public double getR() {

return r;

}

public void setR(double r) {

this.r = r;

}

}

/**

* 台球

* @author qd

*

*/

class Billiards extends Ball {

// 私有成员变量颜色

private String color;

public void setColor(String color) {

this.color = color;

}

// 输出信息

public void printMess(Billiards billiards,Ball ball) {

System.out.println("台球的颜色是:" + billiards.color + "   台球的半径是:" + ball.getR());

}

}

/**

* 公有测试类

* @author qd

*

*/

public class TestBall {

public static void main(String[] args) {

Ball ball = new Ball();

ball.setR(5);

Billiards billiards = new Billiards();

billiards.setColor("白色");

billiards.printMess(billiards,ball);

}

}

7题和8题测试如下:

java构造台球单色和花色,号码分数

1、创建项目在com.tzkt包下面,创建Billiards类继承Jfram实现窗体的创建

2、使用构造函数初始化窗体的基本数据

3、将球桌和台球显示在窗体上

4、让台球以一定的弧度移动起来

写一个最简单的JAVA继承代码??谢谢

可运行的:

import java.awt.*;

import java.awt.event.*;

public class BackJFrame extends Frame{

public BackJFrame(){

super("台球");

setSize(300,300);

setBackground(Color.cyan); //背景

setVisible(true);

addWindowListener(new WindowAdapter()

{

public void windowClosing (WindowEvent e)

{System.exit(0);}

} );

}

public static void main(String args[]){

new BackJFrame();

}

}

标题名称:java台球代码大全 桌球代码
链接分享:https://www.cdcxhl.com/article6/ddgddog.html

成都网站建设公司_创新互联,为您提供网站设计公司电子商务网站改版面包屑导航标签优化小程序开发

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

网站优化排名