黑马程序员技术交流社区

标题: 下面代码,哪个地方有错呢? [打印本页]

作者: 官珺伟    时间: 2014-1-3 14:58
标题: 下面代码,哪个地方有错呢?
本帖最后由 官珺伟 于 2014-1-3 15:17 编辑
  1. class  Count
  2. {
  3.         public static int counter;
  4.         static
  5.         {
  6.                 counter=123;
  7.                 System.out.println("Now in static block.");
  8.         }
  9.         public void test
  10.         {
  11.                 System.out.println("test method=="+counter);
  12.         }
  13. }
  14. public class Test
  15. {
  16.         public static void main(String args[])
  17.         {
  18.                 System.out.println("counter="+Count.counter);
  19.                 new Count().test();
  20.         }
  21. }
  22. //运行结果是:
  23. //Now in static block.counter=123
  24. //test method==123
复制代码


作者: 王清    时间: 2014-1-3 15:06
text()                                             
作者: 几番意难相付    时间: 2014-1-3 15:08
第九行test方法后面少了一对括号
作者: taoge    时间: 2014-1-3 15:14
  1. class  Count
  2. {
  3.         public static int counter;
  4.         static
  5.         {
  6.                 counter=123;
  7.                 System.out.println("Now in static block.");
  8.         }
  9.         public void test() //这里少了()
  10.         {
  11.                 System.out.println("test method=="+counter);
  12.         }
  13. }
  14. public class Test
  15. {
  16.         public static void main(String args[])
  17.         {
  18.                 System.out.println("counter="+Count.counter);
  19.                 new Count().test();
  20.         }
  21. }
  22. //运行结果是:
  23. //Now in static block.
  24. //counter=123
  25. //test method==123
复制代码

作者: 黑马IT学员    时间: 2014-1-3 15:35
对,就是缺少了一个括号,亲!不要犯低级错误
作者: 董月峰    时间: 2014-1-3 17:05
public void test()
第九行test方法后面少了一对括号
作者: 晏勇    时间: 2014-1-4 08:52
第九行test少了个(),建议楼主学习了一段java后用myeclipase做开发,如果你少写了个括号或标点符号它会提示错误。
作者: 净坛使者    时间: 2014-1-4 09:10
亲text()少括号了




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2