public class JIhe {
在昭平等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、成都做網(wǎng)站 網(wǎng)站設(shè)計制作按需制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),營銷型網(wǎng)站建設(shè),外貿(mào)網(wǎng)站建設(shè),昭平網(wǎng)站建設(shè)費用合理。
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());
}
}
Class instrument{
String name; //樂器的名稱
String playStyle; //彈奏風(fēng)格
public void instruPlay(name,playStyle){ //彈奏方法
System.out.println("這個樂器是"+name+",彈奏的風(fēng)格是"+playStyle);
}
}
Class piano extend instrument{
String feeling="鋼琴的聲音好聽?。?; //繼承了instrument類后,變量就不用再寫了,但可以增加一個變量
public void instruPlay("piano","輕音樂"){
System.out.println("這個樂器是"+name+",彈奏的風(fēng)格是"+playStyle+feeling);
}
}
Class violin extend instrument{
String feeling="小提琴的聲音也不錯?。?;
public void instruPlay("violin","melody is happy^_^"){
System.out.println("這個樂器是"+name+",彈奏的風(fēng)格是"+playStyle+feeling);
}
}
很久沒些java代碼了,你測試一下看能不能跑起來,如有問題再問我吧。
第一個:
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("蜘蛛在織網(wǎng)");
}
}
第三個類
public?class?Baigujing?extends?Yaojing?{
public?void?beBeauty(){
System.out.println("白骨精");
}
}
繼承一個類用關(guān)鍵字 extends 就行了 ,
舉個例子: 類A繼承類B ?那么java代碼就是:
public?class?A?extends?B{
}
或者你新建類的時候:
file ?-- new -- class 在彈出框中可以直接輸入要繼承的父類的名字如下圖:
java基礎(chǔ),繼承類題目:編寫一個Java應(yīng)用程序,該程序包括3個類:Monkey類、People類和主類 E
21.編寫一個Java應(yīng)用程序,該程序包括3個類:Monkey類、People類和主類
E。要求:
(1) Monkey類中有個構(gòu)造方法:Monkey (String s),并且有個public void speak()
方法,在speak方法中輸出“咿咿呀呀......”的信息。
(2)People類是Monkey類的子類,在People類中重寫方法speak(),在speak方法
中輸出“小樣的,不錯嘛!會說話了!”的信息。
(3)在People類中新增方法void think(),在think方法中輸出“別說話!認真思考!”
的信息。
(4)在主類E的main方法中創(chuàng)建Monkey與People類的對象類測試這2個類的功
能。、
復(fù)制代碼
package zhongqiuzuoye;
public class Monkey {
Monkey(String s) //構(gòu)造
{}
public void speak()
{
System.out.println("咿咿呀呀......");
}
}