我是 Java 新手。我有以下几组代码。
class Default
{
private short s;
private int i;
private long l;
private float f;
private double d;
private char c;
private String str;
private boolean b;
public static void main (String args[ ])
{
Default df = new Default();
System.out.println("\n Short = "+s);
System.out.println ("\n int i =" + i);
System.out.println ("\n long l =" + l );
System.out.println ("\n float f =" + f);
System.out.println ("\n double d =" + d);
System.out.println ("\n char c =" + c);
System.out.println ("\n String s =" + str);
System.out.println("\n boolean b =" + b);
}
}
这会产生一条错误消息作为此问题的主题,但以下代码可以完美运行。
class Default
{
private short s;
private int i;
private long l;
private float f;
private double d;
private char c;
private String str;
private boolean b;
public static void main (String args[ ])
{
Default df = new Default();
System.out.println("\n Short = "+df.s);
System.out.println ("\n int i =" + df.i);
System.out.println ("\n long l =" + df.l );
System.out.println ("\n float f =" + df.f);
System.out.println ("\n double d =" + df.d);
System.out.println ("\n char c =" + df.c);
System.out.println ("\n String s =" + df.str);
System.out.println("\n boolean b =" + df.b);
}
}
这给出了期望的结果。这两组代码有什么区别。