码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-04-08 22:20:47      阅读:215      评论:0      收藏:0      [点我收藏+]

标签: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();
	}
}

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

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

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

标签:exti   ann   his   class   string   ati   out   logs   imp   

原文地址:http://www.cnblogs.com/lijunzone/p/6683203.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!