Java experimental questions 3_4_ Lindaru equalities station

Source: Internet
Author: User

import Java.util.scanner;abstract class Animal {public String name;public int age ;p ublic float weight;public void Showinfo () {System.out.println ("name:" + THIS.name + "Age:" + this.age+ "Weight:" + thi S.weight);} public abstract void Move ();p ublic 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 codesbird bir = new Bird (name,age,weight); Bir.showinfo (); Bir.move (); Bir.eat ();}} 

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

Note that variables in the parent class are hidden when the variable in the subclass is re-declared;

Java experimental questions 3_4_ Lindaru equalities station

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.