public class JIhe {
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() {
public double getPerimeter() {
public double getDiameter() {
-----------------------------------------------------------------------------------------------------
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(){
——————————————————————————————————————
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();
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;//弹奏风格
public void instruPlay(name,playStyle){//弹奏方法
System.out.println("这个乐器是"+name+",弹奏的风格是"+playStyle);
Class piano extend instrument{
String feeling="钢琴的声音好听!!";//继承了instrument类后,变量就不用再写了,但可以增加一个变量
public void instruPlay("piano","轻音乐"){
System.out.println("这个乐器是"+name+",弹奏的风格是"+playStyle+feeling);
Class violin extend instrument{
String feeling="小提琴的声音也不错!!";
public void instruPlay("violin","melody is happy^_^"){
很久没些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("吃饱了");
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("白骨精");
继承一个类用关键字 extends 就行了 ,
举个例子: 类A继承类B ?那么java代码就是:
public?class?A?extends?B{
或者你新建类的时候:
file ?-- new -- class 在弹出框中可以直接输入要继承的父类的名字如下图:
E.要求:
(1) Monkey类中有个构造方法:Monkey (String s),并且有个public void speak()
方法,在speak方法中输出"咿咿呀呀......"的信息.
中输出"小样的,不错嘛!会说话了!"的信息.
的信息.
能.、
复制代码
package zhongqiuzuoye;
public class Monkey {
Monkey(String s) //构造
{}
public void speak()
{
System.out.println("咿咿呀呀......");
以上就是土嘎嘎小编为大家整理的继承于类java代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!