码迷,mamicode.com
首页 > 编程语言 > 详细

Java 语法 索引 ----- 构造函数(constructor)

时间:2014-08-09 04:52:57      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   div   log   ad   ef   

重载

class MyRectangle{
    int x, y;
    public MyRectangle()             { x = 10; y = 20; }
    public MyRectangle(int a)        { x = a; y = a;   }
    public MyRectangle(int a, int b) { x = a; y = b;   }
}

 

Constructor chaining

public MyRectangle()             { this(10,20);  }
public MyRectangle(int a)        { this(a,a);    }
public MyRectangle(int a, int b) { x = a; y = b; }

Java 语法 索引 ----- 构造函数(constructor),布布扣,bubuko.com

Java 语法 索引 ----- 构造函数(constructor)

标签:style   blog   color   java   div   log   ad   ef   

原文地址:http://www.cnblogs.com/timba/p/3900450.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!