Java job 12 (), java job

Source: Internet
Author: User

Java job 12 (), java job

/* Inheritance and abstract class */package com. baidu. www; abstract class Person {private String name; private int age; public String getName () {return name;} public void setName (String name) {this. name = name;} public int getAge () {return age;} public void setAge (int age) {this. age = age;} public Person (String name, int age) {this. name = name; this. age = age ;}public Person () {super () ;}@ Override public String toString () {return "Person [name =" + name + ", age = "+ age +"] ";} public abstract String speak ();} class ZiXia extends Person {private float score; public ZiXia (String name, int age, float score) {super (name, age); this. setScore (score) ;}@ Override public String speak () {return "Zixia information:" + super. getName () + "" + super. getAge () + "years old" + this. score + "popularity";} public float getScore () {return score;} public void setScore (float score) {this. score = score ;}} class ZhiZunBao extends Person {private float salary; public ZhiZunBao (String name, int age, float salary) {super (name, age); this. setSalary (salary) ;}@ Override public String speak () {return "exclusive information:" + super. getName () + "" + super. getAge () + "years old" + this. salary + "popularity";} public float getSalary () {return salary;} public void setSalary (float salary) {this. salary = salary;} public class GM {public static void main (String [] args) {Person ZiXia = new ZiXia ("fairy", 19,10 ); person ZhiZunBao = new ZhiZunBao ("Person", 18, 10); print (ZiXia. speak (); print (ZhiZunBao. speak ();} private static void print (String speak) {System. out. println (speak );}}

  

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.