夜间福利网站,免费动漫av,一级做a爰片久久毛片免费陪,夜夜骑首页,黄色毛片视频,插插插操操操,综合av色

java之this關(guān)鍵字用法事例解析

時(shí)間:2025-12-23 15:35:29 java語言

java之this關(guān)鍵字用法事例解析

  java之this關(guān)鍵字用法事例解析

  一、this使用范圍

  1、在類的方法定義中使用的this關(guān)鍵字代表調(diào)用該方法對象的引用。

  2、當(dāng)必須指出當(dāng)前使用方法的對象是誰時(shí),要使用關(guān)鍵字this。

  3、有時(shí)使用this可以處理方法中成員變量和參數(shù)重名的`情況。

  4、this可以看做是一個(gè)變量,它的值是當(dāng)前對象的引用。

  注:this一般出現(xiàn)在方法中,當(dāng)方法沒有被調(diào)用時(shí)。并不知道this指向那個(gè)具體的對象。

  當(dāng)某個(gè)對象調(diào)用有this的方法時(shí),this就指向調(diào)用這個(gè)方法的對象。

  二、程序代碼如下:

  public class TestThis{ private int i; public TestThis(int i){ this.i = i; } private TestThis increment(){ i += 1; return this; } public static void main (String[] args){ TestThis mTestThis = new TestThis(100); System.out.println(mTestThis.increment().increment().i); }}

  輸出結(jié)果如下圖所示:


【java之this關(guān)鍵字用法事例解析】相關(guān)文章:

Java中synchronized關(guān)鍵字的用法01-16

解析Java中volatile關(guān)鍵字11-27

Java中final關(guān)鍵字用法的講解03-02

Java關(guān)鍵字及注釋02-16

java關(guān)鍵字復(fù)習(xí)08-22

深入Java關(guān)鍵字null12-01

java的import關(guān)鍵字的使用09-18

理解java中的關(guān)鍵字03-17

Java語言static關(guān)鍵字08-09