private type ..error
can anyone tell me why I get this error?
illegal start of expression
private int confirm;
and also
illegal start of expression
private File soundFile3 = new File("merge.wav");
If I remove the word "private" the compiler doesn't show any errors. The code is part of a public method. Why?
Thank you.
the code is:
private int confirm;
confirm = JOptionPane.showConfi开发者_Python百科rmDialog(this,
"Different sample size....",
"JOin", JOptionPane.OK_CANCEL_OPTION);
if (confirm != JOptionPane.OK_OPTION) {
return;
}
private File soundFile3 = new File("merge.wav");
private keyword cannot be used inside methods. it can be used to declare class fields or methods:
class Foo {
private int num; //private can be specified here
public void foo() {
int s = 1;
int k = num+s; //no private here
}
}
I guess you cannot put an access modifies except final
in a method. It makes no sense to have a private modifier for a method level variable. As methods variables are created in their separate stack and destroyed when the scope is lost.
You should use access modifiers only on class members, not local variables.
Local variables are always visible only in the scope of the block where they were declared. So, if you declare a variable in your method, that variable will be visible only within that method. So, no need to use private
there. I mean, no need even if you could.
精彩评论