[英]Error comes when i call objects from another class i.e. “cannot find symbol”
my program gives error when i try to compile it. 当我尝试编译它时,我的程序给出了错误。 I don't know whats wrong.
我不知道怎么了 Please help me.
请帮我。 It gives error in 21st and 22nd line.
它在21和22行给出错误。 Code is
代码是
class Rectangle {
int length;
int breadth;
void setdata(int x, int y) {
length = x;
breadth = y;
}
int Area() {
int rectarea = length * breadth;
return rectarea;
}
};
class Calculate {
public static void main(String args[]) {
Cal obj = new Cal();
obj.setdata(3, 4);
int result = obj.Area();
System.out.println("Result is " + result);
}
};
It gives error in obj.setdata(3,4);
它在
obj.setdata(3,4);
给出错误obj.setdata(3,4);
and int result=obj.Area();
和
int result=obj.Area();
. 。 Please help me and tell me where i am doing wrong.
请帮助我,告诉我我在哪里做错了。
The name of your class is Rectangle
and not Cal
so replace this piece : 您的班级名称是
Rectangle
而不是Cal
因此,请替换此段:
Cal obj=new Cal();
By: 通过:
Rectangle obj = new Rectangle();
Note 注意
It is not require to set ;
不需要设置
;
after }
like you do in the end of your classes };
在
}
之后,就像在课程结束时一样};
. 。
Hope this can help you 希望这可以帮到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.