• 学习-Java类和对象之类的声明之学生类的定义


    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

    题目:

    任务

    • 定义一个 Student 学生公开类,该类具有学号 id(int),年龄 age(int),grade(int) 等属性;
    • 它们所具有的行为有学习 study(),考试 examination(),讲话 tell(),它们都无返回值和传入的参数。
    • study 方法的功能为换行输出:学号为xx的学生正在学习。
    • examination 方法的功能为换行输出:xx年级正在考试。
    • tell 方法的功能为不换行输出:正在讲话的是一个xx岁的学生。

    编程要求

    仔细阅读右侧编辑区内给出的代码框架及注释,按照提示编写程序代码。

    代码:

    Student.java文件

    1. /**
    2. * 任务:定义一个 Student 学生公开类,该类具有学号 id(int),年龄 age(int),grade(int) 等属性;
    3. * 它们所具有的行为有学习 study(),考试 examination(),讲话 tell(),它们都无返回值和传入的参数。
    4. * 类名为:Student
    5. */
    6. // 请在下面的Begin-End之间按照注释中给出的提示编写正确的代码
    7. /********** Begin **********/
    8. // 第一步:创建一个名为 Student 的公开类
    9. class Student
    10. {
    11. int id;
    12. int age;
    13. int grade;
    14. void study()
    15. {
    16. System.out.println("学号为"+id+"的学生正在学习。");
    17. }
    18. void examination()
    19. {
    20. System.out.println(grade+"年级正在考试。");
    21. }
    22. void tell()
    23. {
    24. System.out.println("正在讲话的是一个"+age+"岁的学生。");
    25. }
    26. }
    27. // 第二步:定义学生的属性
    28. // 第三步:定义学生的行为方法
    29. /********** End **********/

    TestMain.java文件

    1. public class TestMain {
    2. public static void main(String[] args) {
    3. Student student = new Student();
    4. student.age=18;
    5. student.grade=12;
    6. student.id=20110624;
    7. student.study();
    8. student.examination();
    9. student.tell();
    10. }
    11. }

    总结

    提示:这里对文章进行总结:
    例如:以上就是今天要讲的内容,本文仅仅简单介绍了Java类和对象之类的声明之学生类的定义。

  • 相关阅读:
    CSP-J2 2022 游记
    第四章:数据操作Ⅰ 第二节:读写CSV文件
    MySQL 之多版本并发控制 MVCC
    docker部署安装Nginx
    领域驱动设计——精炼
    6. 测度论-期望及其性质
    软件需求怎么写?
    python+nodejs+vue的生鲜交易系统-o2o生鲜商城网站
    C++ 动态规划。。。
    2022ICPC济南站
  • 原文地址:https://blog.csdn.net/m0_65420451/article/details/126573385