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

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

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

时间: 2025-01-19 21:38:55

Java实验题3_4_林大锐格平台的相关文章

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

import java.util.Scanner; class Employee { private String name;// 职员名称 public Employee() { }; public Employee(String s) {// 构造函数,初始化职员名称 this.name = s; } public String GetName() { // 获取职员名称 return name; } } class Manager extends Employee{ String depa

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

import java.util.Scanner; abstract class Vehicle { String wheels; abstract String noOfWheels(String a); void showWheels(){ System.out.println(wheels+" wheel vehicle"); } //write your own codes } class Car extends Vehicle { public String noOfWhee

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

import java.util.Scanner; abstract class Shape{ abstract float GetArea(); abstract float GetPerimeter(); } class Rectangle{ private double x,y; public Rectangle(int i, int j) { x=i; y=j; } public float GetArea(){ return (float)(x*y); } public float G

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

import java.util.Scanner; //write code here class Dog{ String breed,color;int weight; } class SpottedDog extends Dog{ private String spotColor; SpottedDog(String a,int b,String c,String d){ breed=a;weight=b;color=c;spotColor=d; } void showBreed(){ Sy

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

import java.util.Scanner; interface ShowMessage{ void showTradeMark(); } class TV implements ShowMessage{ String a; TV(String a) { this.a=a; } public void showTradeMark() { System.out.println("I am TV "+a); } } public class Main{ public static v

Java练习题4_last_1042林大锐格平台

import java.util.Scanner; public class Main{ public static void main(String args[]){ int ri , repeat; int n; Scanner in = new Scanner(System.in); repeat = in.nextInt(); for(ri = 1 ; ri <= repeat ; ri++){ n=in.nextInt(); dectobin(n); } } static void d

Java练习题4_last-1_1043林大锐格平台

import java.util.Scanner; public class Main{ public static void main(String[] args){ int m , n; Scanner in = new Scanner(System.in); m = in.nextInt(); n = in.nextInt(); System.out.println(Min(m,n)); } static int Min(int a,int b){ if(a<=b)return a; el

Java练习题4_3_2407林大锐格平台

import java.util.Scanner; class Rectangular { private static int x, y; private static int countP = 0; public Rectangular(int xx, int yy) { x=xx; y=yy; } public Rectangular(Rectangular p) { x=p.x; y=p.y; } public int getX() { return x; } public int ge

HDU 1715 大菲波数(JAVA, 简单题,大数)

题目 //BigInteger 和 BigDecimal 是在java.math包中已有的类,前者表示整数,后者表示浮点数 import java.io.*; import java.util.*; import java.math.*; public class Main { /** * @xqq */ public BigInteger an(BigInteger a, BigInteger b, int n) { if(n == 1) { return a; } for(int i = 2