Topic: Java中变量初始化问题 |
Print this page |
1.Java中变量初始化问题 | Copy to clipboard |
Posted by: aiswenjie Posted on: 2007-04-17 09:10 我在一个类中如下定义并初始化变量通过: public class M3 { //定义负荷模型独立参数 private double G=0.039; 改为这样定义却报错,不知为何? public class M3 { //定义负荷模型独立参数 private double G; G=0.039; 提示标记上“;”有语法错误。 |
2.Re:Java中变量初始化问题 [Re: aiswenjie] | Copy to clipboard |
Posted by: xatm092 Posted on: 2007-04-17 10:00 你用了中文的分号? |
3.Re:Java中变量初始化问题 [Re: xatm092] | Copy to clipboard |
Posted by: aiswenjie Posted on: 2007-04-17 10:31 xatm092 wrote: 我的程序里面是英文分号啊,错误依旧。 不知为何? |
4.Re:Java中变量初始化问题 [Re: aiswenjie] | Copy to clipboard |
Posted by: xuxiaolei Posted on: 2007-04-17 12:21 当然不能这样用了,G=0.039可以写在构造函数或者初始化块中或者方法中 可以这样写 public class MyClass { public MyClass() { g = 0.039 } private double g; } 或者这样写 public class MyClass { { g = 0.039; } private double g; } |
5.Re:Java中变量初始化问题 [Re: aiswenjie] | Copy to clipboard |
Posted by: aiswenjie Posted on: 2007-04-17 14:02 多谢楼上的! |
6.Re:Java中变量初始化问题 [Re: aiswenjie] | Copy to clipboard |
Posted by: 112233445566 Posted on: 2007-04-17 22:18 第一次见到这个,回去试一试 { g = 0.039 } |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |