super用法

Person类:

public class Person {
String _name;
int _age;
public Person(String name,int age)
{
_name= name;
_age=age;
}
}

Student类:

public class Student extends Person
{
String _school;
public Student(String name,int age,String school)
{
super(name,age);
_school=school;
} public String GetNameAndAge()
{
return "Name:"+super._name+";Age:"+super._age;
}
}

入口类:

public class ExecStudent {
public static void main(String[] args)
{
Student _student=new Student("zhang san",19,"riben university");
System.out.println("School:"+_student._school);
System.out.println("Name and age:"+_student.GetNameAndAge());
}
}
上一篇:插入随机数到MySQL数据库


下一篇:Androidstudio_LinearLayout