package com.Demo1; public class Test { public static void main(String[] args) { //搞清楚子类构造器为什么要调用父类构造器,有啥应用场景 Teacher t=new Teacher("李四",36,"Java"); System.out.println(t.getName()); System.out.println(t.getAge()); System.out.println(t.getSkill()); } } class Teacher extends People{ private String skill; public Teacher(String name,int age,String skill){ //直接去调用父类的有参构造器 super(name , age); //为skill赋值 this.skill=skill; } public String getSkill() { return skill; } public void setSkill(String skill) { this.skill = skill; } } class People{ private String name; private int age; public People() { } public People(String name, int age) { this.name = name; this.age = 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; } }
标签:name,int,子类,age,常见,构造,skill,public,String From: https://www.cnblogs.com/Karl-hut/p/17438526.html