首页 > 其他 > 详细

this关键字

时间:2018-01-30 16:06:22      阅读:236      评论:0      收藏:0      [点我收藏+]
this:关键字,是当前对象
    1.那个对象调用的,this就具备有那个身份
    2.this可以调用本类中的属性和方法
    3.this可以调用构造方法(本类)
        3.1.this不能调用当前自己的构造方法,会造成死循环
        3.2.this调用构造方法语句必须放在构造方法的首行
        3.3.this构造方法不能形成 闭环

calss Person{
  private String name;
  private int age;

  public Person(String name,int age){
     this.name =  name;            //这是1
     this.age = age;   
}

public Person(){
   // this();         //3.1
   this("aaa",20);     //调用构造方法 ,根据参数来决定调用那个构造方法,
}







//讲一个数字的字符串 变成整形的数值

public calss Test{
    public static void main(String[] args){
          Scanner s = new Scanner(System.in);
           System.out.println("请输入一个数字字符串");
            String num = s.next();
            //利api直接强转  Integer.parseInt(num);

             int length = num.length();
             int sum = 0;
             for(int i=0; i < num.length; i++){
                      char ch = num.charAt(i);
                      int n = ch - 0;
                       sum = sum + n*(int)(Math.pow(10,length - 1));
                        length--;
             }
          System.out.println(sum);
    }

}

 

this关键字

原文:https://www.cnblogs.com/1950137408lxj/p/8384402.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!