java编写继承的代码,java编写继承的代码是什么
用Java继承和多态实现编写代码
代码如下:
创新互联建站主要从事网站制作、成都做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务蚌山,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
abstract class DongWu {
public abstract void info();
}
class Bird extends DongWu {
@Override
public void info() {
System.out.println("我是一只鸟。");
}
}
class Fish extends DongWu {
@Override
public void info() {
System.out.println("我是一条鱼。");
}
}
public class App5 {
public static void main(String[] args) {
DongWu bird = new Bird();
bird.info();
DongWu fish = new Fish();
fish.info();
}
}
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继承代码??谢谢
可运行的:
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编写继承的代码,java编写继承的代码是什么
网页路径:http://azwzsj.com/article/hsdsgh.html