As the name indicates, ultrasonic / level sensors measure distance by using ultrasonic waves.
The sensor head emits an ultrasonic wave and receives the wave reflected back from the target. ultrasonic / level sensors measure the distance to the target by measuring the time between the emission and reception.
An optical sensor has a transmitter and receiver, whereas an ultrasonic / level sensor uses a single ultrasonic element for both emission and reception. In a reflective model ultrasonic / level sensor, a single oscillator emits and receives ultrasonic waves alternately. This enables miniaturisation of the sensor head.