当前位置: 代码迷 >> Java相关 >> [求助]这两个有什么区别?
  详细解决方案

[求助]这两个有什么区别?

热度:211   发布时间:2007-04-16 14:32:46.0
[求助]这两个有什么区别?

public class Class1 {
public static void f (int a,int b)
{
System.out.println("新年快乐!");
}

public class Class1 {
public static f()
{
inta int b
System.out.println("新年快乐!");
}
初学者,我什么都不知道,很想知道void f (int a,int b)
static f()
{inta int b
}
有什么区别


----------------解决方案--------------------------------------------------------
区别是 static f()无法通过编译 这样定义方法是错误的 必须有返回值
static 是关键字有它实现的方法是静态方法 void是返回值类型
----------------解决方案--------------------------------------------------------

第一个为什么可以,后面的是不是要返回值?


----------------解决方案--------------------------------------------------------
问题怎么解决啊?
----------------解决方案--------------------------------------------------------
public static f()
这个好像要求有返回类型吧
可以加上public static (int/void/String等类型) f()

----------------解决方案--------------------------------------------------------