• Java--学生类(成员变量,成员方法直接输出学生信息)




    /*package gl;

    //建立学生类xs
    class xs{

    //数据成员变量
    int xh;
    String xm;
    String xb;
    int nl;

    //成员方法
    public void showxs() {
    System.out.println("学号:"+xh);
    System.out.println("姓名:"+xm);
    System.out.println("性别:"+xb);
    System.out.println("年龄:"+nl);
    }
    }
    public class gl {

    
    

    public static void main(String[] args) {
    // TODO Auto-generated method stub

    
    


    //成员赋值
    xs xs1= new xs();
    xs1.xh=119509228;
    xs1.xm="周月";
    xs1.xb="女";
    xs1.nl=19;

    xs1.showxs();


    }
    }*/
    //构造方法,一次性输入
    package gl;
    //建立学生类xs
    class xs{

    //数据成员变量
    int xh;
    String xm;
    String xb;
    int nl;

    xs(int xh1,String xm1,String xb1,int nl1){
    xh=xh1;
    xm=xm1;
    xb=xb1;
    nl=nl1;
    }

    //成员方法
    public void showxs() {
    System.out.println("学号:"+xh);
    System.out.println("姓名:"+xm);
    System.out.println("性别:"+xb);
    System.out.println("年龄:"+nl);
    }
    }
    public class gl {

    
    

    public static void main(String[] args) {
    // TODO Auto-generated method stub

    
    


    //成员赋值
    xs xs2 = new xs(119509228,"周月","女",19);

    xs2.showxs();


    }
    }

     
  • 相关阅读:
    二叉树同构
    L1-001 Hello World--java
    关于Hanoi的递归分析
    L1-049 天梯赛座位分配
    1001 害死人不偿命的(3n+1)猜想 && 1005 继续(3n+1)猜想
    L1-046 整除光棍
    L1-043 阅览室
    lambda_Consumer接口
    lambda_Supplier接口
    Veu_v-for
  • 原文地址:https://www.cnblogs.com/zhouxiaoyue/p/14170874.html
Copyright © 2020-2023  润新知