Mass is proportional to the number of unit particles in a given object, whereas density is mass per unit bulk (n-dimensional volume). But bulk is a dimension-dependent quantity: it has different units in every dimension! So one should not confuse 2D density with 3D density (or density in any other dimension): they have different units! In 2D, bulk is measured in terms of unit distance squared -- if we standardize on meters, say, then 2D bulk has units m
2. But in 3D, bulk is measured in terms of m
3. Thus, in 2D, density is measured in terms of units per m
2, that is, m
-2, whereas in 3D, density is measured in terms of units per m
-3, that is, m
-3. Since these two quantities have different units, they are incomparable. Similarly, with 4D density we're dealing with m
-4, which is again incomparable with the other two densities.
Calculating mass from density involves multiplying with the bulk of the object, which, again, is a dimension-dependent quantity. A 2D object has bulk measured in terms of m
2, whereas a 3D object has bulk measured in terms of m
3. So it's invalid to compare 2D bulk with 3D bulk: the units are incompatible! Similarly, you can't meaningfully compare 3D bulk with 4D bulk, because their units are different.
Note, however, that mass itself is a dimensionless quantity, so it's something that could be applied across dimensions. But you can't meaningfully derive mass from density without getting into trouble across dimensions, since then the dimensionality of space enters into the equation and you end up with incomparable units.
As to what mass
is, that's a pretty deep philosophical question.
Technically, we can't measure mass directly -- we can infer its value based on other measurements, such as density (which unfortunately is dimension-dependent), weight (which is force-dependent -- so when in orbit you're weightless, but that by no means implies that you're massless!), acceleration (deducing mass by measuring trajectories), inertia, etc.. In fact, one of the mysteries of the universe is why inertial mass -- that is, an object's resistance to change in velocity -- is identical to gravitational mass -- the object's response to the force of gravity.
Consider this: mass is just one of the scalar properties of an object, but (electrical) charge is another scalar property. For example, you can in theory have an object that consists of protons without any electrons, and have a positively-charged thing. Now consider how a generic object X responds to some generic force F. Presumably, any given object X "feels" the force F to a certain degree, depending on some inherent characteristics it has. A positively-charged particle responds to the electrical force from a negatively-charged particle differently from, say, a negatively-charged particle. And the amount of reaction you get depends on how positively/negatively-charged it is. A highly-positive object will respond very strongly to an electromagnetic field F, whereas a neutral (zero charged) object doesn't respond at all. So then, it would seem that an object X has a number of "parameters", that characterize how much it responds to certain forces. If X has electrical charge q, for example, then it would "feel" an external electrical force in a way proportional to q. So one would expect that gravity, being a distinct force from inertia (via, say, a rocket engine), should be associated with a distinct parameter on X than inertia. The object X should have an inertial mass M_i, which tells us how strongly it resists changes in velocity, and a distinct gravitational mass M_g, which tells us how strongly it reacts to the force of gravity, just as it has a distinct parameter q (i.e., electrical charge), that tells us how strongly it reacts to an electromagnetic field.
However, what we find is that M_i = M_g always. This is a very strange observation, since on the surface, inertia and gravity are two unrelated things, so why should all objects respond the same way to gravity as they do to inertia, whereas they
don't respond to the electromagnetic force the same way (you almost never find q=M_i or q=M_g)? The fact that inertial mass is always equal to gravitational mass is a strange coincidence that suggests that perhaps inertia and gravity aren't different things after all. Perhaps they are just two aspects of the same thing! This is what led Einstein to discover general relativity, where this coincidence is explained by postulating that gravity is simply curvature in space itself, and thus objects under the influence of gravity are actually travelling in a straight line just as before, except that due to the curvature of space, this "straight line" is actually crooked. In other words, gravity changes the trajectory of objects not by exerting some external force on them, but by changing the local meaning of "straight line" in the object's frame of reference! So, from the object's point of view, its path is still dictated by the law of inertia just like before, and so it will react according to its inertial mass M_i. That's why M_i = M_g: gravity isn't a different force that operates on the object, but just a bending of space that changes the inertial behaviour of the object, that's why the object reacts according to its inertial mass, instead of some other quantity!
But then if we're talking about the curvature of space, then we're back to dependence on the dimensionality of space -- because after all, the kinds of ways that space can curve depends on how many dimensions it has. So what
is mass??! Intuitively speaking, it's the amount of "stuff" in an object -- but what does that mean across different dimensions of space? It seems intuitively obvious, but if you look at it carefully, it's actually quite mysterious! Elementary particles like electrons have mass -- but, as far as we know, they have no discernible shape or structure, so they seem to be point-masses. Which is another mystery, because it would appear that they are 0D dimensionless points, yet they have non-zero mass! Which then begs the question, is an electron in 3D different from an electron in 4D? Is mass a quantity that can be meaningfully compared across dimensions? For example, if 4D electrons are different from 3D electrons, then wouldn't it be meaningless to compare their masses, since a 4D electron can't exist in 3D space and therefore it's impossible to weigh them both to see which one is more massive? But if they
are comparable -- that is, if electrons exist in both 3D and 4D, then they would have to be the same object, just confined to a different dimension of space; in which case, one may ask, can an electron exist in spaces of arbitrary dimensions? Can it exist
outside of space itself as an independent entity? No matter what the answers are, it seems far from clear what "mass" means across different dimensions, and it's not obvious at all whether they are even comparable!