Questions tagged «restriction»

21
“ static”关键字在课程中做什么?
具体来说,我正在尝试以下代码: package hello; public class Hello { Clock clock = new Clock(); public static void main(String args[]) { clock.sayTime(); } } 但是它给了错误 无法在静态方法main中访问非静态字段 所以我将声明更改为clock: static Clock clock = new Clock(); 而且有效。将关键字放在声明之前是什么意思?就可以对对象执行的操作而言,它将确切地执行和/或限制什么?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.