class B {
int x,y;
int z;
z=x*y;
void show() {
System.out.println(z);
}
}
class A {
public static void main(String as[]) {
B b=new B();
b.show();
}
}
class B { int x,y; int z; z=x*y; void show() { System.out.println(z); } }
Share
You can’t have statements in the class body (
z=x*y;). You have (at least) two options:int z = x * y;use initializer block
These are virtually the same. I’d prefer the first option (cleaner) See here