Illigitimate births

I have been told that one reason for illigitimate births was because young men had to serve in the military and only officers could marry. If they married later the church gave the children the fathers name.