When you compile B then the Java compiler tries to find all associated classes in order to create a runnable program. If it cannot find the A.class file, but it can find the A.java file then it will build the class automatically. Try running the command
java -verbose B.java
and you will see it in action.