JAVA Programming :: Basic Concepts - Discussion
Home > JAVA Programming > Basic Concepts > MCQs Questions Discussion
12 / 64
What will happen when you attempt to compile and run the following code?
public class MyField{
String s;
public static void main(String argv[]){
MyField m = new MyField();
m.amethod();
}
void amethod(){
System.out.println(s);
}
}
public class MyField{
String s;
public static void main(String argv[]){
MyField m = new MyField();
m.amethod();
}
void amethod(){
System.out.println(s);
}
}
ACompile time error s has not been initialised
BRuntime error s has not been initialised
CBlank output
DOutput of null
Answer: Option (Login/Signup)
Show Explanation
The above code will compile fine, no problem in that, but the output will be null, since variable 's' has not been initialized with some value.
Hence, output will be null.
Asked In ::
STEP-BY-STEP
The above code will compile fine, no problem in that, but the output will be null, since variable 's' has not been initialized with some value.
Hence, output will be null.
Read Full Answer
Report Error
Please Login First Click Here