public class A {
int a; //--1--
public short getB() {
short b; //--2--
return b; //--3--
}
public static void main(String[] args) {
System.out.print(new A().a); // --4--
System.out.println(new A().getB());
}
}
Compilation error will occur in line 3 because of the usage of local variable b that is not initialised.
The error will NOT occur in line 4 since the class field is initialised with zero by default.
Login in to like
Login in to comment