码迷,mamicode.com
首页 > 其他好文 > 详细

类名+函数名(参数1,参数2.....){.......return this;}

时间:2015-12-20 18:56:12      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

下述的函数是这样定义的: 类名+函数名参数1,参数2.....{.......return this;}

                                   int +函数名(参数1,参数2.....){.......return int;}

                                   short+函数名(参数1,参数2.....){.......return short;}

                                   double+函数名(参数1,参数2.....){.......return double;} 

                                  String+函数名(参数1,参数2.....){.......return String;} 

                                   int[]+函数名(参数1,参数2.....){.......return int[];}

                                   String[]+函数名(参数1,参数2.....){.......return String[];

                                   void+函数名(参数1,参数2.....){...................................} 

 1 import java.awt.Point;
 2   class rectangle
 3     { int x1=0;
 4       int y1=0;
 5       int x2=0;
 6       int y2=0;
 7      
 8      rectangle point(int x,int y,int z,int w)
 9       {x1= x;
10        y1= y;
11        x2= z;
12        y2= w;
13        return this;
14        }
15      rectangle point(Point topleft,Point rightbottom)
16       {x1=topleft.x;
17        y1=topleft.y;
18        x2=rightbottom.x;
19        y2=rightbottom.y;
20        return this;
21         }
22       rectangle point(Point topleft,int w,int h)
23        { x1= topleft.x;
24          y1= topleft.y;
25          x2= topleft.x + w;
26          y2= topleft.y - h;
27         return this;
28         }
29       public static void main(String[] args)
30 
31        { rectangle experiment = new rectangle();
32          experiment.point(1,2,3,4);
33          System.out.print(experiment.x1+" "+experiment.y1+" "+experiment.x2+" "+experiment.y2);
34          experiment.point(new Point(1,2),new Point(3,4));
35          System.out.print(experiment.x1+" "+experiment.y1+" "+experiment.x2+" "+experiment.y2);
36          experiment.point(new Point(1,2),3,4);
37          System.out.print(experiment.x1+" "+experiment.y1+" "+experiment.x2+" "+experiment.y2);
38         }
39    
40    }

 

类名+函数名(参数1,参数2.....){.......return this;}

标签:

原文地址:http://www.cnblogs.com/lubocsu/p/5061425.html

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