4.8 JAVA

Source: Internet
Author: User

Class person{
private String name;
Private String addr;
private char sex;
private int age;

public void SetName (String name) {
THIS.name = name;
}
public void setaddr (String addr) {
this.addr = addr;
}
public void Setsex (char sex) {
This.sex = sex;
}
public void Setage (int.) {
This.age = age;
}

Public person (String name,string Addr,char sex,int age) {
This.setname (name);
This.setaddr (addr);
This.setsex (Sex);
This.setage (age);
}
Public person (String Name,int age) {
This.setname (name);
This.setage (age);
}
Public person () {}

Public String GetInfo () {
Return "Name:" +this.name+
"; Addr: "+this.addr+
"; Sex: "+this.sex+
"; Age: "+this.age;
}

public void Say () {
System.out.println (This.getinfo ());
}
}


Class Student extends person{
private int math;
private int 中文版;

public void Setmath (int math) {
This.math = Math;
}
public void setenglish (int 中文版) {
This.english = 中文版;
}

Public Student (String name,string addr,char sex,int age,int math,int 中文版) {
Super (Name,addr,sex,age);
This.math = Math;
This.english = 中文版;
}
Public Student (String Name,int age) {
Super (Name,age);
}
Public Student () {};

Public String GetInfo () {
return Super.getinfo () +
"; Math: "+this.math+
"; 中文版: "+this.english;
}

public void Say () {
Super.say ();
}
}

public class test6{
public static void Main (string[] args) {
Person per1 = new Person ("Lisi", 27);
Person stu1 = new Student ("Jhy", "Beijing", ' G ', 20,98,91);
Student stu2= New Student ("Zjx", "Beijing", ' M ', 20,98,82);
Per1.say ();
Stu1.say ();
Stu2.say ();
}
}

4.8 JAVA

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.