重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
public class JIhe {
成都创新互联是专业的丰满网站建设公司,丰满接单;提供网站设计、成都网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行丰满网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
private String color;
private String dateCreated;
private String filled;
public String getColor() {
return color;
}
public String getDateCreated() {
return dateCreated;
}
public String getFilled() {
return filled;
}
public void setColor(String color) {
this.color = color;
}
public void setFilled(String filled) {
this.filled = filled;
}
@Override
public String toString() {
return "Color:" + this.color +" filled:" + this.filled + "detaCreated:" + dateCreated;
}
}
------------------------------------------------------------------------------------------------------------
public class Circle extends JIhe {
private double radius;
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double getArea() {
return 3.14 * this.radius * this.radius;
}
public double getPerimeter() {
return 2 * 3.14 * this.radius;
}
public double getDiameter() {
return 2 * this.radius;
}
}
-----------------------------------------------------------------------------------------------------
public class Rectangle extends JIhe {
private double width;
private double height;
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getArea(){
return this.width * this.height;
}
public double getPerimeter(){
return this.width * 2 + this.height * 2;
}
}
——————————————————————————————————————
public class Test {
public static void main(String[] args){
Circle circle = new Circle();
circle.setRadius(1.0);
System.out.println(circle.getArea());
System.out.println(circle.getColor());
System.out.println(circle.getDateCreated());
System.out.println(circle.getDiameter());
System.out.println(circle.getFilled());
System.out.println(circle.getPerimeter());
System.out.println(circle.getRadius());
Rectangle r = new Rectangle();
r.setHeight(2.0);
r.setWidth(4.0);
System.out.println(r.getArea());
System.out.println(r.getColor());
System.out.println(r.getDateCreated());
System.out.println(r.getFilled());
System.out.println(r.getHeight());
System.out.println(r.getPerimeter());
System.out.println(r.getWidth());
}
}
java基础,继承类题目:编写一个Java应用程序,该程序包括3个类:Monkey类、People类和主类 E
21.编写一个Java应用程序,该程序包括3个类:Monkey类、People类和主类
E。要求:
(1) Monkey类中有个构造方法:Monkey (String s),并且有个public void speak()
方法,在speak方法中输出“咿咿呀呀......”的信息。
(2)People类是Monkey类的子类,在People类中重写方法speak(),在speak方法
中输出“小样的,不错嘛!会说话了!”的信息。
(3)在People类中新增方法void think(),在think方法中输出“别说话!认真思考!”
的信息。
(4)在主类E的main方法中创建Monkey与People类的对象类测试这2个类的功
能。、
复制代码
package zhongqiuzuoye;
public class Monkey {
Monkey(String s) //构造
{}
public void speak()
{
System.out.println("咿咿呀呀......");
}
}
可运行的:
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();
}
}
第一个:
public class Yaojing {
protected String name;
protected int age;
protected String gender;
public void showBasicInfo() {
System.out.println(toString());
}
public void eatTangSeng() {
System.out.println("吃饱了");
}
@Override
public String toString() {
return "Yaojing [name=" + name + ", age=" + age + ", gender=" + gender + "]";
}
}
第二个类
public class Zhizhujing extends Yaojing {
public void buildNet(){
System.out.println("蜘蛛在织网");
}
}
第三个类
public class Baigujing extends Yaojing {
public void beBeauty(){
System.out.println("白骨精");
}
}
package extend;
/**
* 圆类
* @author 枫雅
* 2019年3月21日
*/
public class Circle {
private double r;
public final static double PI = 3.14;
public Circle(double r) {
this.r = r;
}
public double Circumference(double r) {
return 2*PI*r;
}
public double Area(double r) {
return PI*r*r;
}
}
package extend;
/**
* 圆柱类,继承自圆类
* @author 枫雅
* 2019年3月21日
*/
public class Cylinder extends Circle{
private double h;
public Cylinder(double r, double h) {
super(r);
this.h = h;
}
public double CeArea(double r, double h) {
return super.Circumference(r)*h;
}
public double Volume(double r, double h) {
return super.Area(r)*h;
}
}
package extend;
/**
* 圆锥类,继承自圆柱类
* @author 枫雅
* 2019年3月21日
*/
public class Cone extends Cylinder{
public Cone(double r, double h) {
super(r, h);
}
public double CeArea(double r, double h) {
return super.CeArea(r, h)/2;
}
public double Volume(double r, double h) {
return super.Volume(r, h)/3;
}
}
package extend;
/**
* 测试类
* @author 枫雅
* 2019年3月21日
*/
public class Test {
public static void main(String[] args) {
double r = 3;
double h = 2;
Circle circle = new Circle(r);
System.out.println("半径为:" + r + " 圆的周长为:" + circle.Circumference(r));
System.out.println("半径为:" + r + " 圆的面积为:" + circle.Area(r));
Cylinder cylinder = new Cylinder(3, 2);
System.out.println("底部半径为:" + r + ",高为:" + h + " 圆柱的侧面积为:" + cylinder.CeArea(r, h));
System.out.println("底部半径为:" + r + ",高为:" + h + " 圆柱的体积为:" + cylinder.Volume(r, h));
Cone cone = new Cone(3, 2);
System.out.println("底部半径为:" + r + ",高为:" + h + " 圆锥的侧面积为:" + cone.CeArea(r, h));
System.out.println("底部半径为:" + r + ",高为:" + h + " 圆锥的体积为:" + cone.Volume(r, h));
}
}