Hi all, for the following codes:
class Fruit{}
class Apple extends Fruit{}
class Orange extends Fruit{}
public class Over
{
public static void main(
String [] arg)
{
Apple a=new Apple(); // 1
//Fruit a=new Apple(); //2
System.out.println ( a instanceof Orange) ;
}
}
I would get an compile error where I expected to be false.
If I comment the line 1 and uncomment line 2, I would get the result.
Why is it?