关注
class Student
{
protected String name;//姓名
protected int age;//年龄
private static int num = 0;
public Student(String name,int age)
{
if(name != null)
this.name = name;
else
this.name ="Student " + num++;
if(age >= 0)
this.age = age;
else
this.age = 0;
}
public void show()
{
System.out.println(this.name + "的年龄是:" + this.age);
}
}
class Undergraduate extends Student
{
private String degree;//学位
public Undergraduate(String name,int age,String degree)
{
super(name,age);
this.degree = degree;
}
public void show()
{
System.out.println(this.name + "的年龄是:" + this.age + ",学位是:" + this.degree);
}
}
public class Test
{
public static void main(String[] args)
{
Student s1 = new Student("小明",23);
Student s2 = new Student("小米",36);
Student s3 = new Student("小亮",12);
Student s4 = new Undergraduate("小红",37,"博士");
Student s5 = new Undergraduate("小辉",25,"本科");
s1.show();
s2.show();
s3.show();
s4.show();
s5.show();
}
}
查看原帖
点赞 1
相关推荐
01-24 15:42
吉林大学 Java
冰炸橙汁_不做oj版:就第一个项目而言纯堆技术栈啊,没有量化成果支撑,培训班味太浓,罗列了一堆中间件,但是只用了极大提升、显著降低这种词,而且你所谓的ai改造就存在于标题中,ai具体怎么用的是一点没说啊 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 春招什么时候投? #
7887次浏览 130人参与
# 实习到现在,你最困惑的一个问题 #
3283次浏览 101人参与
# 春节前,你还在投简历吗? #
10949次浏览 135人参与
# 牛友的春节生活 #
4636次浏览 120人参与
# 牛客AI体验站 #
14190次浏览 262人参与
# 春节提前走,你用什么理由请假? #
7251次浏览 181人参与
# 从夯到拉,锐评职场mentor #
3272次浏览 55人参与
# 备战春招/暑实,现在应该做什么? #
3138次浏览 110人参与
# 聊聊Agent开发 #
20668次浏览 537人参与
# 距离春招还有一个月,你现在是什么开局? #
4935次浏览 99人参与
# 暑期实习什么时候投? #
5540次浏览 136人参与
# 推荐一个值得做的AI项目 #
5673次浏览 161人参与
# 用一句话形容你的团队氛围 #
38819次浏览 284人参与
# 总结:offer选择,我是怎么选的 #
258633次浏览 1508人参与
# 腾讯工作体验 #
568614次浏览 3715人参与
# 我的AI电子员工 #
27761次浏览 186人参与
# 实习的内耗时刻 #
221610次浏览 1644人参与
# 字节跳动工作体验 #
705877次浏览 6306人参与
# 实习想申请秋招offer,能不能argue薪资 #
218854次浏览 1171人参与
# AI“智障”时刻 #
25661次浏览 127人参与
查看12道真题和解析