新聞中心
java 類(lèi)的繼承,求大神給代碼
public class JIhe {
成都創(chuàng)新互聯(lián)是專(zhuān)業(yè)的豐滿(mǎn)網(wǎng)站建設(shè)公司,豐滿(mǎn)接單;提供網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行豐滿(mǎn)網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
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());
}
}
求編寫(xiě)一個(gè)Java類(lèi)的繼承程序?
java基礎(chǔ),繼承類(lèi)題目:編寫(xiě)一個(gè)Java應(yīng)用程序,該程序包括3個(gè)類(lèi):Monkey類(lèi)、People類(lèi)和主類(lèi) E
21.編寫(xiě)一個(gè)Java應(yīng)用程序,該程序包括3個(gè)類(lèi):Monkey類(lèi)、People類(lèi)和主類(lèi)
E。要求:
(1) Monkey類(lèi)中有個(gè)構(gòu)造方法:Monkey (String s),并且有個(gè)public void speak()
方法,在speak方法中輸出“咿咿呀呀......”的信息。
(2)People類(lèi)是Monkey類(lèi)的子類(lèi),在People類(lèi)中重寫(xiě)方法speak(),在speak方法
中輸出“小樣的,不錯(cuò)嘛!會(huì)說(shuō)話(huà)了!”的信息。
(3)在People類(lèi)中新增方法void think(),在think方法中輸出“別說(shuō)話(huà)!認(rèn)真思考!”
的信息。
(4)在主類(lèi)E的main方法中創(chuàng)建Monkey與People類(lèi)的對(duì)象類(lèi)測(cè)試這2個(gè)類(lèi)的功
能。、
復(fù)制代碼
package zhongqiuzuoye;
public class Monkey {
Monkey(String s) //構(gòu)造
{}
public void speak()
{
System.out.println("咿咿呀呀......");
}
}
寫(xiě)一個(gè)最簡(jiǎn)單的JAVA繼承代碼??謝謝
可運(yùn)行的:
import java.awt.*;
import java.awt.event.*;
public class BackJFrame extends Frame{
public BackJFrame(){
super("臺(tái)球");
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繼承問(wèn)題 求代碼
第一個(gè):
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?+?"]";
}
}
第二個(gè)類(lèi)
public?class?Zhizhujing?extends?Yaojing?{
public?void?buildNet(){
System.out.println("蜘蛛在織網(wǎng)");
}
}
第三個(gè)類(lèi)
public?class?Baigujing?extends?Yaojing?{
public?void?beBeauty(){
System.out.println("白骨精");
}
}
java程序繼承
package?extend;
/**
*?圓類(lèi)
*?@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;
/**
*?圓柱類(lèi),繼承自圓類(lèi)
*?@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;
/**
*?圓錐類(lèi),繼承自圓柱類(lèi)
*?@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;
/**
*?測(cè)試類(lèi)
*?@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?+?"?圓的周長(zhǎng)為:"?+?circle.Circumference(r));
System.out.println("半徑為:"?+?r?+?"?圓的面積為:"?+?circle.Area(r));
Cylinder?cylinder?=?new?Cylinder(3,?2);
System.out.println("底部半徑為:"?+?r?+?",高為:"?+?h?+?"?圓柱的側(cè)面積為:"?+?cylinder.CeArea(r,?h));
System.out.println("底部半徑為:"?+?r?+?",高為:"?+?h?+?"?圓柱的體積為:"?+?cylinder.Volume(r,?h));
Cone?cone?=?new?Cone(3,?2);
System.out.println("底部半徑為:"?+?r?+?",高為:"?+?h?+?"?圓錐的側(cè)面積為:"?+?cone.CeArea(r,?h));
System.out.println("底部半徑為:"?+?r?+?",高為:"?+?h?+?"?圓錐的體積為:"?+?cone.Volume(r,?h));
}
}
新聞名稱(chēng):java繼承的程序代碼,java繼承的實(shí)現(xiàn)
文章轉(zhuǎn)載:http://www.ef60e0e.cn/article/hejojp.html