zoukankan      html  css  js  c++  java
  • Java 类和对象3

    编写Java应用程序。首先,定义描述学生的类——Student,包括学号(int)、姓名(String)、年龄(int)等属性;二个方法:Student(int stuNo,String name,int age)

    用于对对象的初始化,outPut()用于输出学生信息。其次,再定义一个主类—TestClass,在主类的main方法中创建多个Student类的对象,使用这些对象来测试Student类的功能。

     1     //创建类
     2     int stuNo;
     3     String stuName;
     4     int stuAge;
     5     //构造方法
     6     student(int stuNo,String name,int age)
     7     {
     8         this.stuNo=stuNo;
     9         stuName=name;
    10         stuAge=age;
    11     }
    12     void outPut()
    13     {
    14         System.out.println(stuName+"	"+stuNo+"	"+stuAge);
    15     }
    16     
    17     public static void main(String[] args) {
    18         student xs1=new student(10001,"张三",25);
    19         student xs2=new student(10002,"李四",27);
    20         student xs3=new student(10003,"王五",22);
    21         student xs4=new student(10004,"马六",19);
    22         student xs5=new student(10005,"冯七",22);
    23         student xs6=new student(10006,"秦八",26);
    24         
    25         System.out.println("姓名:	学号:	年龄:");
    26         xs1.outPut();
    27         xs2.outPut();
    28         xs3.outPut();
    29         xs4.outPut();
    30         xs5.outPut();
    31         xs6.outPut();
    32     }

    运行结果:

  • 相关阅读:
    Leetcode 290 Word Pattern
    Leetcode 205 Isomorphic Strings
    Leetcode 345 Reverse Vowels in a String
    Leetcode 151 Reverse Words in a String
    Leetcode 344 Reverse String
    Leetcode 383 Ransom Note
    leetcode 387 First Unique Character in a String
    反码补码和位运算
    SpringBoot进阶
    布隆过滤器
  • 原文地址:https://www.cnblogs.com/ouyangtangfeng99/p/5501336.html
Copyright © 2011-2022 走看看