I have gone through this thread What causes and what are the differences between NoClassDefFoundError and ClassNotFoundException? This is what one of the ans,which has max u
One of cases where NoClassDefFoundError occur is when the Class JVM is trying to access is not found in classpath. But if class is present in classpath, It will result in ClassNotFoundException.
In short NoClassDefFoundError will come if a class was present during compile time but not available in java classpath during runtime.
Just try to run with explicit -classpath option where the classpath does not contain class B.