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

this关键字的构造方法的使用

时间:2016-09-19 15:50:54      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

 1 package com.wh.Object3;
 2 
 3 public class this_Demo {
 4     private String name;
 5     private double price;
 6     private int num;
 7 
 8     public String getName() {
 9         return name;
10     }
11 
12     public void setName(String name) {
13         this.name = name;
14     }
15 
16     public double getPrice() {
17         return price;
18     }
19 
20     public void setPrice(double price) {
21         this.price = price;
22     }
23 
24     public int getNum() {
25         return num;
26     }
27 
28     public void setNum(int num) {
29         this.num = num;
30     }
31 
32     public this_Demo() {
33         //this关键字的构造方法的使用 
34         this("可乐", 2.5, 1001);
35     }
36 
37     public this_Demo(String name, double price, int num) {
38         this.name = name;
39         this.price = price;
40         this.num = num;
41     }
42 
43     public static void main(String[] args) {
44         /*
45          * this("","",""); 代表一个构造方法
46          */
47         this_Demo th=new this_Demo();
48         System.out.println(th.getName());
49         System.out.println(th.getPrice());
50         System.out.println(th.getNum());
51     }
52 }

 

this关键字的构造方法的使用

标签:

原文地址:http://www.cnblogs.com/1020182600HENG/p/5885263.html

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