When I join objects they are getting all same material as the target object. That's why I don't like. I need them to have different materials. How do I prevent this ?
Nothing simpler. If you want to insert several materials in the same composition, just select the entire object and switch to edit mode. Once this is done you just have to select the interested parts and in the material editor assign a certain material to the selection, same thing with the rest of the object, the selection again, create a new material and assign it to the selection.
In the screenshot (1) I posted you can see how the parallelepiped is actually formed by two joined cubes, and in the material editor you can see the presence of two materials associated with different meshes of the same object.
- Bonus tip:There are actually other ways, [see Gif. (2) ] if you don't want to merge the object and leave the meshes separate you can link the two objects. in the sense that although the meshes are separate, the interactions of one of the two objects will affect the corresponding linked. Which will represent the aspect of parents-children, where the influential object is the parent and it will be he who commands the movements etc. This will allow you in your example to move the base of the donut and with it the icing and the sugars that will follow the movements of the donut, being able to apply different textures and materials.
To make the parent link, use the shortcut CTRL + P and click on Object or with Keep Transform which allows you to maintain the original positions, bearing in mind that the parent will be applied to the object with the light yellow selection and not to the orange one. I hope I was helpful.