首页 > 代码库 > 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_林大锐格平台
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。