I believe it's because you have declared your "o" variable as being of the "One" type.
Change your code to this, and it should compile
Object o = new One();
if(o instanceof Two) {
System.out.println("Yes");
} else {
System.out.println("No");
}
The instanceof operator is meant to be used when you don't know the type in advance. So when you have an object of something that comes in through a method parameter, or when your variable is declared with the type of a base class and want to have different behavior per subclass type. In the scenario you've provided, the compiler can tell you at compile time that what you wrote will never be true, and does so.
Edit: the if(false)
compiles, because a lot of people use a pattern like this:
public class Application{
private static final boolean DEBUG = true;
public static void main(String args[]){
if(DEBUG){
System.out.println("Debugging information");
}
}
}
Now imagine a large application where this sort of pattern is repeated in several places. If the compiler would refuse to compile this, it would be much harder to switch from and to DEBUG mode.
In my earlier explanation, maybe I shouldn't have used the words "the compiler can tell you at compile time that what you wrote will never be true". A better description would be "The compiler can tell that what you're writing does not make sense".