class Demothis关键字//哪个对象在调用this所在的函数,this就代表哪个对象。
{           //当定义类中功能时,该函数内部要用到该函数的对象时,这时用this来表示这个对象。
  public static void main(String[] args)
  {
    Person P1=new Person(23);
    Person P2=new Person(24);
    boolean b=P1.compare(P2);
    System.out.println(b);
  }
}
class Person
{
  private int age;
  Person(int age)
  {
    this.age=age;
  }

Person(String name)
  {
    this.name=name;
  }

Person(String name,int age)
  {
    this(name);//this语句只能放语句的第一行: this(name);   this.name=name;    对的      this.name=name; this(name);  错的

    this.age=age;
  }
  public boolean compare(Person P)
  {
    return this.age==P.age;//注意==强制赋值,不然不同类型无法转换: 不兼容的类型: int无法转换为boolean:return this.age=P.age;
  }
}

最新文章

  1. 萌新笔记——封装hiredis——C++与redis对接(一)(string的SET与GET操作)
  2. 初学者--bootstrap(四)栅格系统----在路上(8)
  3. php版本引起的const问题
  4. python中几个常见的黑盒子之“字典dict” 与 “集合set”
  5. ant打包命令
  6. Effective Objective-C 2.0 笔记三(Literal Syntax简写语法)
  7. ESFramework ——可堪重任的网络通信框架
  8. DEDECMS开启邮箱验证通知的解决方法
  9. Orleans之EventSourcing
  10. 解决fiddler无法抓取本地部署项目的请求问题
  11. LabelFrame
  12. CSS布局十八般武艺都在这里了
  13. winrar+目录穿透复现
  14. XamarinSQLite教程添加测试数据
  15. Codeforces Round #281 (Div. 2) D(简单博弈)
  16. MFC树形控件的使用(右键点击)
  17. Arduino 串口输出LM35温度
  18. URL传值乱码
  19. Java工具类(util) 之01- 数学运算工具(精确运算)
  20. Caliburn.Micro - Getting Started - Introduction

热门文章

  1. 模仿console自写函数打印js的对象
  2. JavaScript高级程序设计-第六章面向对象的程序设计
  3. 【引】objective-c,6:Autorelease Pool
  4. php的一些问题
  5. @SuppressWarnings("deprecation")
  6. PHP中的运算符---位运算符、递增递减运算符、三元运算符、字符串运算符、数组运算符、类型运算符、错误控制运算符
  7. Python第三方包的安装和管理
  8. 支付宝Andfix 原理解析
  9. NetflixOSS:Hollow正式发布
  10. java 线程安全 synchronized