1.) 编译器自动进行转化 - double - 可以接受 byte, int, float, long 等类的初始值。 float - byte, int etc.float f = 0; // OK. - 0 is an int. float f = 0.0; // Error! - 0.0 is a double! float f = 0L; // Error! - 0L is a long! double d = 0L; // OK2.) Do not mix the 'static' in C funtion with 'static' in Java. static - in Java, the memeber belong to the class, not the object. static - in C's funtion, remember the value after function called.If you want to use something like 'static' in C, the best way to implement this is to use an object variable.
我想再问一下,在内部类中不能声明静态成员,但是,如果在静态内部类中是不是可以声明静态成员了呢?我编译运行了一下,没有出错。下面是例子: public class Outer { public static class Inner { static int i=5; } }//这是一个含有静态成员的内部类 public class Test { public static void main(String[] args) { Outer.Inner oi=new Outer.Inner(); } }//测试这个类 请问这个怎么解释?
不过,局部变量设置为static类型,解释得我还是有点不太明白
llsoft(天堂鱼),尽管设置成static型,不是局部变量了,但是如果我一定要这么用,为什么编译不过去呢?
而局部变量一般是在栈里面分配的,除非你自己申请在堆里面分配。
函数执行完,栈中的东西就没了。
double - 可以接受 byte, int, float, long 等类的初始值。
float - byte, int etc.float f = 0; // OK. - 0 is an int.
float f = 0.0; // Error! - 0.0 is a double!
float f = 0L; // Error! - 0L is a long!
double d = 0L; // OK2.) Do not mix the 'static' in C funtion with 'static' in Java.
static - in Java, the memeber belong to the class, not the object.
static - in C's funtion, remember the value after function called.If you want to use something like 'static' in C, the best way to implement this is to use an object variable.
public class Outer
{
public static class Inner
{
static int i=5;
}
}//这是一个含有静态成员的内部类
public class Test
{
public static void main(String[] args)
{
Outer.Inner oi=new Outer.Inner();
}
}//测试这个类
请问这个怎么解释?