That depends on the railway operator. Be sure to check the railway operator's conditions before you travel. Please note: The ticket vendor is sometimes different from the railway operator. For example, SBB sells tickets for ÖBB/Nightjet night trains - the conditions of ÖBB/Nightjet apply to these. You can see who the railway operator is by looking at the train labelling (e.g. NJ for Nightjet). A quick Google search will help if necessary.
(as of August 2024)