java面试题

当前位置: 面试问题网 > java面试题 > this关键字的作用

this关键字的作用

this关键字表示的是“当前对象”,当出现在类的实例方法中,代表的是调用该方法的对象;当出现在类的构造方法中时,代表的是调用该构造方法创建的对象。在下列两种情况下,必须使用this:
   方法的形式参数与类的成员变量同名:
   例如:
   class Person{
   String name;
   int age;
   public Person(String name, int age){
   this.name=name;
   this.age=age;
   }
   }
  
   一个类中的构造器调用同一个类中的另一个构造器:
   调用的方法:
   this([参数列表]) //处于构造器的第一行位置上
   例如:
   class Person{
   String name;
   int age;
   public Person(String name){
   this.name=name;
   }
   public Person(String name, int age){
   this(name); //调用另一构造器,必须放在第一条语句位置上
   this.age=age;
   }
   }

【this关键字的作用】相关文章

1. this关键字的作用

2. this关键字的含义

3. 关键字throw与throws的用法差异

4. JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?

5. super关键字的用法

6. static关键字的用法

7. 请解释virtual关键字的含义

8. What is the purpose of Void class? Void类的作用是什么?

9. Python中pass语句的作用是什么

10. swtich是否能作用在byte上,是否能作用在long上,是否能作用在String上

本文来源:https://www.mianshiwenti.com/a12492.html

点击展开全部

《this关键字的作用》

将本文的Word文档下载到电脑,方便收藏和打印

推荐程度:

进入下载页面

﹝this关键字的作用﹞相关内容

其它栏目

也许您还喜欢