java对象的交互
2015-09-15 15:49
393 查看
package display; public class Display { private int value = 0; private int limit = 0; public Display(int limit) { this.limit=limit; } public void increase() { value++; if(value==limit) { value = 0; } //System.out.println(value); } public int getvalue() { return value; } public static void main(String[] args) { // TODO Auto-generated method stub Display time = new Display(60); time.increase(); } }在另一个类中调用上一个类的函数:
package display; public class Clock { private Display hour = new Display(24); private Display minute = new Display(60); public void start() { while(true){ minute.increase(); if(minute.getvalue()==0) { hour.increase(); } System.out.printf("%02d:%02d\n",hour.getvalue(),minute.getvalue()); } } public static void main(String[] args) { // TODO Auto-generated method stub Clock clock = new Clock(); clock.start(); } }
相关文章推荐
- java学习之List集合
- 【Java基础】--算法与数组
- spring mvc学习(一)
- JAVA中如何使用log4j作为日志记录工具
- Spring MVC基于注解的Controller
- javax.servlet.jsp.JspException cannot be resolved to a type
- 用 java 写一个计算器
- java.util.concurrent 学习笔记(1)
- JDK环境变量配置
- Maven学习记录5——Eclipse添加maven依赖找不到maven库中的jar
- javac 编译
- 【leetcode】ZigZag Conversion【java】
- How to remove the action suffix extension in Struts 2
- Eclipse上自己生成的keystore,出现错误“Keystore was tampered with, or password was incorrect”的一种解决办法
- springMvc get参数转码
- JAVA设计模式之单例模式
- Struts 2 – Development mode example
- 在java servlet中获得session中保存对象的值。
- 七牛---用JAVA生成各种凭证代码
- Struts 2 Namespace configuration example and explanation