public class Student
{
private String name;
private int age;
private String college;
public Student()
{
age = 20;
}
public Student(String name)
{
this();//can not be call Student,only use this() method.
this.name = name;
System.out.println("this student name is "+name);
}
public Student(String name,String college)
{
this(name);//C++中可以直接用Student(name)调用其他构造函数
this.college = college;
System.out.println("this student name is "+name+" college is "+college);
}
public Student upgrade()
{
age++;
return this;
}
public void print()
{
System.out.println("name is: "+name
+" age is: "+age
+" college is: "+college);
}
public static void main(String[] args)
{
Student student1 = new Student("linc");
Student student2 = new Student("linc","shenyang college");
student2.upgrade().print();
}
}
public class ClassLeader extends Student
{
private String duty;
public ClassLeader()
{
duty = "class monitor";
}
public ClassLeader(String duty,String name,String college)
{
super(name,college);
this.duty = duty;
}
public void print()
{
super.print();
System.out.println("duty is " + duty);
}
public static void main(String[] args)
{
ClassLeader leader = new ClassLeader("life","linc","shenyang");
leader.print();
}
}
D:\workspace\Java\project261\super>javac -d . *java D:\workspace\Java\project261\super>java ClassLeader
this student name is linc this student name is linc college is shenyang name is: linc age is: 20 college is: shenyang duty is life
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有