2021-04-26

package hhh;

class Person

{

static int count=0;

protected String name;

protected int age;

public Person(String n1,int a1)

{

name=n1;

age=a1;

count++;

}

public Person(String n1) {

this(n1,0);

}

public Person(int a1) {

this("未知名",a1);

}

public Person() {

this("未知名");

}

public void print() {

System.out.print(this.getClass().getName()+" ");

System.out.print("两个参数的构造方法被调用count="+this.count+" ");

System.out.println(" "+name+","+age);

}

}

public class hhhh extends Person{

protected String dept;

hhhh(String n1,int a1,String d1){

super(n1,a1);

dept=d1;

}

public static void main(String args[]) {

Person p1=new Person("王小红",21);

p1.print();

hhhh s1=new hhhh("王帅",19,"计算机");

s1.print();

}

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容