The corporate authorities of any town or city and the county commission of any county may each establish, within the town or city or within the county, hospitals, temporary or permanent, for the reception of the sick or infirm or of persons suspected of having infectious or contagious diseases, and may make all needful rules and regulations for the control and management thereof and may confer by contract upon any institution for the instruction of students of medicine located in the city, town or county in which such hospital is situated, upon such terms and for such number of years as they may determine, the right to select the visiting staff of physicians to such hospital for the collegiate course of each year and to hold clinics on the patients therein and have its students attend such clinics. The corporate authorities and the county commission may unite in the establishment of such hospitals, if deemed expedient, making them common for the use of the town or city and of the county, and in the making of rules and regulations for the control and management thereof and shall jointly have the same powers and authority above conferred upon each.