提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
题目:
任务:
- 定义一个 Student 学生公开类,该类具有学号 id(int),年龄 age(int),grade(int) 等属性;
- 它们所具有的行为有学习 study(),考试 examination(),讲话 tell(),它们都无返回值和传入的参数。
- study 方法的功能为换行输出:
学号为xx的学生正在学习。; - examination 方法的功能为换行输出:
xx年级正在考试。; - tell 方法的功能为不换行输出:
正在讲话的是一个xx岁的学生。。
编程要求
仔细阅读右侧编辑区内给出的代码框架及注释,按照提示编写程序代码。
代码:
Student.java文件
/**
* 任务:定义一个 Student 学生公开类,该类具有学号 id(int),年龄 age(int),grade(int) 等属性;
* 它们所具有的行为有学习 study(),考试 examination(),讲话 tell(),它们都无返回值和传入的参数。
* 类名为:Student
*/
// 请在下面的Begin-End之间按照注释中给出的提示编写正确的代码
/********** Begin **********/
// 第一步:创建一个名为 Student 的公开类
class Student
{
int id;
int age;
int grade;
void study()
{
System.out.println("学号为"+id+"的学生正在学习。");
}
void examination()
{
System.out.println(grade+"年级正在考试。");
}
void tell()
{
System.out.println("正在讲话的是一个"+age+"岁的学生。");
}
}
// 第二步:定义学生的属性
// 第三步:定义学生的行为方法
/********** End **********/TestMain.java文件
public class TestMain {
public static void main(String[] args) {
Student student = new Student();
student.age=18;
student.grade=12;
student.id=20110624;
student.study();
student.examination();
student.tell();
}
}总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了Java类和对象之类的声明之学生类的定义。
版权声明:本文为m0_65420451原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。