标签:exti ann his class string ati out logs imp
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();
}
}
************************************************************************************
注意,子类中的变量重新申明的话会隐藏父类中的变量;
标签:exti ann his class string ati out logs imp
原文地址:http://www.cnblogs.com/lijunzone/p/6683203.html