Can anyone point out what is wrong with this code:
class A {
A(){
}
}
class B extends A {
B(){
}
}
class TestInstanceof {
public static void main(
String a[]){
A a = new A();
B b = new B();
if(a instanceof b){
System.out.println("A is instance of B");
} else {
System.out.println("A is not instance of B");
}
if(b instanceof a){
System.out.println("B is instance of A");
} else {
System.out.println("B is not instance of A");
}
}
}
I get a compliation error:
C:\TestInstanceof.java:26: a is already defined in main(java.lang.String[])
A a = new A();
^
C:\TestInstanceof.java:29: cannot resolve symbol
symbol : class b
location: class TestInstanceof
if(a instanceof b){
^
C:\TestInstanceof.java:39: cannot resolve symbol
symbol : class a
location: class TestInstanceof
if(b instanceof a){
^
3 errors
Tool completed with exit code 1