The oil in Saudi Arabia will not be exhausted by 2040. Estimates give it far longer than that; it is the Gulf Countries that are more limited in their reserves. As for the meat of the question, e.g. what will happen to the Saudi economy when the reserves are, it will depend on how the income has been invested. Saudi Arabia has historically been slower to diversify its portfolio and, if current investment trends continue, Saudi Arabia will have a sharp decline following the exhaustion of its reserves.
The economy of Saudi Arabia is dependent on oil and has strong government control over major economic activities. The Saudi economy is the largest in the Arab world. Saudi Arabia has the world's second-largest proven petroleum reserves and the country is the largest exporter of petroleum. It has also the fifth-largest proven natural gas reserves. Saudi Arabia is considered an "energy superpower". It has third highest total estimated value of natural resources, valued at US$34.4 trillion in 2016
Venezuela has the largest petroleum reserves in the world.
Saudi Arabia is Asia's leader in petroleum production and petroleum reserves
Saudi Arabia has the most oil reserves in the world
Countries that are major producers of petroleum include the United States, Saudi Arabia, Russia, and Canada. These countries have large reserves and significant production capabilities.
According to the CIA World Fact Book, the main export of Saudi Arabia is petroleum: "Saudi Arabia has an oil-based economy with strong government controls over major economic activities. It possesses about 20% of the world's proven petroleum reserves, ranks as the largest exporter of petroleum, and plays a leading role in OPEC. The petroleum sector accounts for roughly 80% of budget revenues, 45% of GDP, and 90% of export earnings."
The Middle East region, particularly countries like Saudi Arabia, Iraq, and Iran, has the most petroleum reserves in the world. This region holds a significant portion of the global oil reserves and is a major exporter of petroleum products.
I have included to related links. The 3 largest producers of petroleum are Saudi Arabia, Russia and the US. However, the US consumes its production. The countries with the largest reserves of oil are Saudi Arabia, Canada and Iran.
Saudi ArabiaProven oil reserves (billion barrels):267.91Total oil supply in 2012 (thousand barrels per day): 11,545.7Saudi Arabia has almost one-fifth of the world's proven oil reserves and ranks as the largest producer and exporter of oil in the world.
Saudi Arabia primarily has a market economy, but has many similarities with other petro-states which have an economy that is primarily fueled and driven by petroleum as opposed to industry and commerce.
the economy of saudi arabia is very nice, because this country are rich in many establishment, their country can provide the good quality of many products exactly the petroleum business.
Without petroleum, Saudi Arabia would be a relatively insignificant backwater country, indistinguishable from most African countries.