private static int total = 0; private static final int MAX = 10; private static int swamp(int[] ary, int ind1, int ind2) { .... }all above three are legal. as a matter of fact, when a static method invokes other method in the class, or uses other variable in the Class, that variable or method has to be static regardless it's public, protected or private.
static静态修饰符,在静态方法中必须引用静态的变量
我想楼主的意思应该是 void func(int Arg) { static int lastArg=0; ... }上面的lastArg只在func中使用,似乎没必要放到class中,这样程序会更加清楚吧
这叫什么鬼话主语?你学过语文没有?
难道你每说一句话都要分清主谓宾?
static只能修饰成员变量
不能修饰方法中的变量
private static final int MAX = 10;
private static int swamp(int[] ary, int ind1, int ind2)
{
....
}all above three are legal.
as a matter of fact, when a static method invokes other method in the class, or uses other variable in the Class, that variable or method has to be static regardless it's public, protected or private.
void func(int Arg)
{
static int lastArg=0; ...
}上面的lastArg只在func中使用,似乎没必要放到class中,这样程序会更加清楚吧
至于局部变量(方法内的变量)是不可以声明为static。
你想把程序写的大时就知道
写小时是否要管private
public,protected.的关系吗。我认为没必要