i am trying to understand why this won’t run. I am thinking that I may need to import a package. I would also like to know what happens in the class LocalVariables on the the line myObject.f();
I think that I have just instantiated myObject on the previous line but am I calling the f method with myObject.f(); ????? I don’t understand what is supposed to happen on that line.
Any help would be appreciated.
class MyObject{
static short s = 400; //static variable
int i = 200; //instance variable
void f() {
System.out.println("s = " + s);
System.out.println("i = " + i);
short s = 300; //local variable
int i = 100; //local variable
double d = 1E100; //local variable
System.out.println("s = "+s);
System.out.println("i = " +i);
System.out.println("d = " + d);
}
}
class LocalVariables{
public static void main(String[] args){
MyObject myObject = new MyObject();
myObject.f();
}
}
1 Answer