📄 student.java
字号:
/** 一个应用程序,用来演示对象做一个方法的返回值
* @作者:尉哲明
* @日期:2001年5月 */
/** Date类 */
class Date{
int year;
int month;
int day;
/** 构造方法 */
Date(int y,int m,int d){
year=y;
month=m;
day=d;
}
/** showDate()方法 */
void showDate(){
System.out.println(year+","+month+","+day);
}
}//Date类结束
/** Student类 */
public class Student{
private String no;
private String name;
private Date birth;
/** 初始化方法 */
void setStu(String s1,String s2,int y,int m,int d){
no=s1;
name=s2;
birth=new Date(y,m,d);
}
/** getBirth()方法 */
Date getBirth(){ //定义getBirth方法,该方法用来返回birth变量值
return birth;
}
/** main()方法 */
public static void main(String args[]){
Student stu=new Student();
stu.setStu("0001","wang",1975,6,6);
System.out.print("birth = ");
stu.getBirth().showDate();
/*调用stu的getBirth方法得到stu的birth对象,然后再调用该对象的showDate方法显示其值 */
}
}//Student类结束
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -