It is done similar to MS-Windows.
It is not done by OS. It is done by file manager, a part of the windowing system. Usually the part of the file-name after the last dot . is used to make the decision. There is a way to set them in settings, or when you right click on a file.
So the file does not tell the OS, the file is not active so can do nothing on its own, but the file manager looks at the file-name, the file manager could also look inside the file much as the file utility does.