A pencil partly immersed in water in a glass tumbler appears to be displaced at the interface of air and water because:
of refraction of light
When light rays travel from one medium to another, its direction changes because of the change in speed of light in different medium. This phenomenon is known as refraction of light.
In the figure shown below, a ray of light coming from the lower end X of the pencil travels from water to the air and gets refracted away from normal as it travels from denser to rarer medium. Another ray coming from X will also get refracted in the same way. The two refracted rays, when produced backward, appear to meet at point Y as shown in the figure. Thus, a virtual image is formed at Y.
Hence, the pencil is actually straight but on immersing in water, it appears to be displaced at the interface of air and water due to refraction.