Why is this so? Let's first discuss the definition of density and why objects sink. Density refers to the amount of matter contained in a given space or volume. When there's more amount of matter in a given space or volume, the object is then considered denser and at the same time heavier. However, this doesn't mean that density and weight is the same and can be used interchangeably.
Weight refers to the vertical force exerted by a mass of object when subjected to gravity. Unlike density, weight is dependent on the amount of gravity in a particular place. To make it clearer, let's take the egg as an example. The egg's density remains the same no matter where you bring it, whatever the amount of gravity is in that place. However, if you bring the same egg to space, where there is no gravity, it loses its weight! But its density remains the same. That's the difference between density and weight - gravity.
Why Objects Float or Sink
Now let's go back to the question of why objects float or sink. Placing an object that's denser than fresh water automatically sinks. In our Salt Water Egg experiment, because the egg is denser than tap water, it pushes away water particles so it can make space for itself hence the sinking motion. But in the case of the salt water, since it is heavier than ordinary tap water, it is more capable of holding the egg up - hence the egg floating. In easier words, objects sink when their own density is greater than the liquid's density.