代碼
提交代碼
public class ImoocStudent {
// 定義屬性(特征)
String nickname; // 昵稱
String position; // 職位
String city; // 城市
String sex; // 男 | 女
// 定義方法(行為)
public void studyCourse() {
System.out.println("學習課程");
}
public void postComment() {
System.out.println("發(fā)表評論");
}
public void postArticle() {
System.out.println("發(fā)表手記");
}
public static void main(String[] args) {
// 實例化學生對象
ImoocStudent student = new ImoocStudent();
// 調(diào)用并打印成員屬性
System.out.println("昵稱:" + student.nickname);
System.out.println("職位:" + student.position);
System.out.println("城市:" + student.city);
System.out.println("性別:" + student.sex);
// 調(diào)用成員方法
student.studyCourse();
student.postComment();
student.postArticle();
}
}
運行結(jié)果