zoukankan      html  css  js  c++  java
  • this关键字

    class emp
    {private int empno ;
     private String ename;
     private String job ;
     private double sal ;
     public emp(){
       this(1,"张三","前台",100);
       }
     public emp (int empno){
       this(empno,"李四","后台",2000);
       }
     public emp(int empno,String ename){
       this(empno,ename,"程序员",10000);
       }
     public emp(int empno,String ename,String job,double sal){
       this.empno=empno;
       this.ename=ename;
       this.job=job;
       this.sal=sal;
       }
     public String getInfo(){
       return "编号"+this.empno+",姓名:"+ this.ename+ ",职位:" + this.job + ",工资:" + this.sal ;
       }
    }
    public class indone
    {public static void main(String args[]){
       emp ea = new emp();
       emp eb = new emp(2);
       emp ec = new emp(3,"德玛西亚");
       emp ed = new emp(4,"上帝","万能的程序员",50000);
       System.out.println(ea.getInfo());
        System.out.println(eb.getInfo());
           System.out.println(ec.getInfo());
           System.out.println(ed.getInfo());
       }
    }
    this一定要放在构造方法的首行
  • 相关阅读:
    【程序2】
    【程序1】
    基数排序
    归并排序
    选择排序
    leetcode15
    leetcode221
    leetcode322
    leetcode921
    leetcode922
  • 原文地址:https://www.cnblogs.com/shuaiqiyang/p/5853913.html
Copyright © 2011-2022 走看看