public class test2 { /**
* @param args
*/
public static void main(String[] args) {
circlesquare mystyle =new circlesquare(5);
System.out.println("the area is "+mystyle.b());
}
}class circlesquare{
circlesquare(int x){
int m=2;
int y=x;
}
int b(){
return y*m;
}}
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
y cannot be resolved to a variable
m cannot be resolved to a variable at circlesquare.b(test2.java:22)
at test2.main(test2.java:11)
Java类String
* @param args
*/
public static void main(String[] args) {
circlesquare mystyle =new circlesquare(5);
System.out.println("the area is "+mystyle.b());
}
}class circlesquare{
circlesquare(int x){
int m=2;
int y=x;
}
int b(){
return y*m;
}}
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
y cannot be resolved to a variable
m cannot be resolved to a variable at circlesquare.b(test2.java:22)
at test2.main(test2.java:11)
Java类String
* @param args
*/
public static void main(String[] args) {
circlesquare mystyle = new circlesquare(5);
System.out.println("the area is " + mystyle.b());
}
}class circlesquare {
circlesquare(int x) {
int m = 2;
int y = x;
} int b() {
return y * m;
}
}在方法b里,根本没有定义y和m这两个变量,怎么能使用呢?
int m=2;
int y;
circlesquare(int x){
m=2;
y=x;
}
int b(){
return y*m;
}}
经过指点,改正过来了。谢谢。
{ /**
* @param args
*/
public static void main(String[] args)
{
circlesquare mystyle = new circlesquare(5);
System.out.println("the area is " + mystyle.b());
}}class circlesquare
{
int m;
int y;
circlesquare(int x)
{
m = 2;
y = x;
} int b()
{
return y * m;
}}
y和m应该写成累的成员变量