2
任何人都可以告诉我为什么这个工程?任务是添加最低限度的静态关键字以使此代码有效。静态与method1和method2我可以理解,但为什么把它添加到int步?为什么这段代码有效?任务添加静态关键字
/* Minimum number of static keywords
Add the minimum number of static keywords to make the code compile and the program to successfully complete.
*/
public class Solution {
public static int step; //static was added here
public static void main(String[] args) {
method1();
}
public static void method1() { //static was added here
method2();
}
public static void method2() { //static was added here
new Solution().method3();
}
public void method3() {
method4();
}
public void method4() {
step++;
for (StackTraceElement element : Thread.currentThread().getStackTrace())
System.out.println(element);
if (step > 1) return;
main(null);
}
}
哇多么可怕的代码示例。谁对你造成了这种情况? –
不需要*编译*,但需要使其终止......但是作为T.J.克劳德说,这是非常可怕的。 –
可怕的原因是什么?这只是来自java培训课程的一些任务 – genek