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

构建器——《Thinking in Java》随笔001

时间:2017-02-26 14:18:26      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:void   inf   str   nbsp   new   创建   rgs   thinking   pac   

package cn.skyfffire;

/**
 * 
 * @author skyffire
 *
 */
class Tree {
    int height;
    
    Tree() {
        prt("无参数构造");
    }
    
    Tree(int i) {
        prt("创建Class Tree使用Integer参数" + i);
        
        height = i;
    }
    
    Tree(String s) {
        prt(s);
    }
    
    void info() {
        prt("Tree 值:" + height);
    }
    
    static void prt(String s) {
        System.out.println(s);
    }
}

public class Test {
    public static void main(String[] args) {
        Tree aTree = new Tree("hhh");
        Tree bTree = new Tree(1);
        
        aTree.info();
        bTree.info();
    }
}

 

构建器——《Thinking in Java》随笔001

标签:void   inf   str   nbsp   new   创建   rgs   thinking   pac   

原文地址:http://www.cnblogs.com/skyfffire/p/6444150.html

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