2021-04-21

class Person{

protected String name;

protected int age;

void setdate(String n1,int a1)

{

name=n1;

age=a1;

}

public void print()

{

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

}

}

public class Student extends  Person{

protected String dept;

public static void main(String args[])

{

Person p1 =new Person ();

p1. setdate("张军",21);

p1.print();

Student s1 =new Student();

s1.setdate("王丽华",20);

s1.dept="计算机系";

s1.print();

}

}

你可能感兴趣的:(2021-04-21)