首页 > 代码库 > Java实验题3_4_林大锐格平台

Java实验题3_4_林大锐格平台

import java.util.Scanner;

abstract class Animal {
    public String name;
	public int age;
	public float weight;

	public void showInfo() {
		System.out.println("name:" + this.name + " age:" + this.age
				+ " weight:" + this.weight);
	}

	public abstract void move();

	public abstract void eat();
}

class Bird extends Animal {
	
	Bird(String a,int b,float c){
		this.name=a;
		this.age=b;
		this.weight=c;
	}
	public void showInfo() {
		System.out.println("name:" + this.name + " age:" + this.age
				+ " weight:" + this.weight);
	}
	public void move(){
		System.out.println(name+" Fly");
	}
	public void eat(){
		System.out.println(name+" Eat insects");
	}
    //write your own codes
}

public class Main {
	public static void main(String[] args) {
		String name;
		int age;
		float weight;
		Scanner scanner = new Scanner(System.in);
		name = scanner.next();
		age = scanner.nextInt();
		weight = scanner.nextFloat();
        //write your own codes
		Bird bir = new Bird(name,age,weight);
		bir.showInfo();
		bir.move();
		bir.eat();
	}
}

  ************************************************************************************

注意,子类中的变量重新申明的话会隐藏父类中的变量;

Java实验题3_4_林大锐格平台