歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Java this關鍵字用在構造方法中

Java this關鍵字用在構造方法中

日期:2017/3/1 10:35:55   编辑:Linux編程

this 關鍵字用在構造方法中。

[java]
  1. package com.han;
  2. /**
  3. * this 關鍵字用在構造方法中。
  4. * @author han
  5. *
  6. */
  7. public class ThiSUSE {
  8. public ThisUse() {
  9. this("this調用無參構造方法之前先調用有參構造方法");
  10. //it is equivalent to : new ThisUse("this調用無參構造方法之前先調用有參構造方法");
  11. System.out.println("this調用無參構造方法");
  12. }
  13. public ThisUse(String name) {//構造方法重載
  14. System.out.println(name);
  15. }
  16. @SuppressWarnings("unused")
  17. public static void main(String[] args) {
  18. // TODO Auto-generated method stub
  19. ThisUse object=new ThisUse();
  20. }
  21. }
Copyright © Linux教程網 All Rights Reserved