博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
this关键字的构造方法的使用
阅读量:4678 次
发布时间:2019-06-09

本文共 1178 字,大约阅读时间需要 3 分钟。

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 }

 

转载于:https://www.cnblogs.com/1020182600HENG/p/5885263.html

你可能感兴趣的文章
20145204《信息安全系统设计基础》第3周学习总结
查看>>
Longest Common Prefix
查看>>
InstallShield 2012 Spring新功能试用总结
查看>>
二进制转换,八进制,十六进制转换
查看>>
Django项目部署
查看>>
新的一年,让我们携手前行
查看>>
基于VC++2012在Windows8上实现文件隐藏
查看>>
两个服务器上SQLServer实例之间配置Service Broker示例
查看>>
数据结构
查看>>
在你的代码中使用自定义异常类
查看>>
SVN合并时报错:Merge tracking not allowed with missing subtrees; try restoring these items
查看>>
超强干货,11个灰常实用的AI设计小技巧!
查看>>
bzoj 4827 礼物
查看>>
JSP 学习笔记
查看>>
Python Byte类型(API系列)
查看>>
ActiveMQ学习笔记(4)----JMS的API结构和开发步骤
查看>>
ImportError: No module named 'requests'
查看>>
[VS调试]VS2010 VS2012调试时显示加载符号导致调试特别慢
查看>>
外部python脚本调用django 手动清理session
查看>>
C数组和指针
查看>>