the difference is not the declaration itself, it‘s the data path that will hold and maintain the resulting property. In the given example, you will be able to access the prop from bpy.context.wm.myprop. Note that what you have effectively done here is to extend the type WindowManager by an additional property. This can be done with ID types (such as bpy.types.Object, bpy.types.Scene,…).
If you define it in the body of a class, and the class is properly registered, the prop will be accessed from instances of said class. So for example, if your class defines an operator which registers as a mesh operator, you will see your property as bpy.ops.mesh.my_operator.myprop. Note that in this case, you have defined an entirely new operator, instead of extending an existing one with a prop.