Let William be x years old.
Thomas = (4 + x) years
In five years,
William = (x + 5) years
Thomas = 4 + x + 5 = (9 + x) years
Given, in five years sum of their ages is 24.
x + 5 + 9 + x = 24
2x + 14 = 24
2x = 24 - 14
2x = 10
x =

x = 5
Hence, William is 5 years old and Thomas is 9 years old.