Thinking in Java 4th 习题2.1

Thinking in Java 4th

题目描述: Create a class containing an int and a char that are not intitialized and print their values to verify that Java performs default initialization.


自己的想法是先new个类,存放私有属性,然后用主函数类调用,结果出现右侧private访问受限问题,然后去掉private后又出现找不到或无法加载错误。懵了一回突然发现是命令调用时多了.java敲打。改之,结果如下:

Thinking in Java 4th 习题2.1_第1张图片


然后这是随书给出的代码,尴尬

// TIJ4 Chapter Object, Exericise 1, page 89
// object/PrimitiveTest.java
// Create a class containing an int and a char that are not intitialized
// and print their values to verify that Java performs default initialization.

public class PrimitiveTest {
    static int i;
    static char c;    
    public static void main(String[] args) {        
        System.out.println("int = " + i);
        System.out.println("char = " + c);
    }
}


总结:过多依赖类,思想有点僵化,能不新建类就不要浪费资源


你可能感兴趣的:(java,in,Thinking,4th)