java教程继承例子代码,java继承的代码实例

java 类的继承,求大神给代码

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() {

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继承代码??谢谢

可运行的:

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编写动物世界的继承关系代码

我写了一个,内容比较简单的。代码如下:public class AnimalTest {

Animal animal;

public void eat(Animal animal){

animal.eat();

}

public void walk(Animal animal){

animal.walk();

}

public static void main(String args[]){

Animal animal=new Animal("animal");

Wolf w=new Wolf("wolf");

Goat g=new Goat("goat");

AnimalTest at=new AnimalTest();

at.eat(animal);

at.eat(w);

at.eat(g);

at.walk(animal);

at.walk(w);

at.walk(g);

}

}

class Animal {

String name;

public Animal(String name){

this.name=name;

}

public Animal(){}

public void setName(String name){

this.name=name;

}

public String getName(){

return name;

}

public void eat(){

System.out.println("animal eat");

}

public void walk(){

System.out.println("animal walk");

}

public String toString(){

return name;

}

}class Wolf extends Animal {

public Wolf(String name){

super(name);

}

public Wolf(){}

public void eat(){

System.out.println("wolf eat meat");

}

public void walk(){

System.out.println("wolf walk");

}

public String toString(){

return name;

}

}class Goat extends Animal {

public Goat(String name){

super(name);

}

public Goat(){}

public void eat(){

System.out.println("goat eat grass");

}

public void walk(){

System.out.println("goat walk");

}

public String toString(){

return name;

}

}


文章名称:java教程继承例子代码,java继承的代码实例
网页路径:http://azwzsj.com/article/hcojss.html