This question already has an answer here:
I've just started learning guitar, having only ever played piano, and this really confuses me.
On a piano, to play a C major triad chord I simply hit C, E, and G...I don't hit any other notes or it's a different chord.
But on guitar, you hold down the frets on some strings and leave the rest open and you strum and you call it a chord even though all those open strings are getting thrown in there too! It's a major triad plus a bunch of other notes!
Why does it still sound good? You could never do that on the piano. Why do guitar chords seem to work differently?