标签:java类 lan student 相对 派生类 object 间接 rgb main
一、继承性的优点
二、继承性的格式
class A extends B{}
A:子类、派生类、subclass
B:父类、超类、基类、superclass
class Person{ private String name; private int age; public void setName(String name){ this.name = name ; } public String getName(){ return name; } public void setAge(int age){ this.age = age ; } public int getAge(){ return age ; } } class Student extends Person{ private String school ; public void setSchool(String school){ this.school = school ; } public String getSchool(){ return school ; } } public class Test{ public static void main(String args[]){ Student stu = new Student(); stu.setName("小学生");//父类方法 stu.setAge(18);//父类方法 stu.setSchool("蓝翔挖掘机专修学院"); //自身方法 System.out.println(stu.getName()+"、" + stu.getAge() + "、" + stu.getSchool()); } }
三、java中关于继承性的规定
四、补充
标签:java类 lan student 相对 派生类 object 间接 rgb main
原文地址:https://www.cnblogs.com/dorsher/p/14767051.html