Interaction of topology and the Picard group of Algebraic surfaces It is well known that a smooth cubic surface $X\subset \mathbb{P}^3$ has exactly 27 lines in it. Furthermore, it is easy to check that Picard group $$Pic(X)\cong \mathbb{Z}^7$$ Here the generators are lines which are $\mathbb{P}^1$ topologically. Furthermore, it is easy to check that $$\chi_{top}(X)=2+H_2(X)=9$$Topologically speaking, notice that as smooth manifold $X$ has no 1-skeleton. This makes the 2-dimensional cells glue to points along their bounday, getting spheres $\mathbb{P}^1$ as the result of this gluing process. 
My first question is why the other 20 lines do not contribute to the Euler characteristic of $X$.
Going further, if $X\subset \mathbb{P}^3$ has degree 4, it is known that $X$ sometimes has lines, sometimes it does not. However, $$\chi_{top}(X)=2+H_2(X)=24$$ meaning that, despite the fact that $X$ can perfectly have no lines, we still have homology $H_2$ which are spheres topologically! meaning, there are in fact spheres (due to the argument above which says that $X$ has no 1-skeleton). Besides $\chi_{top}$ is constant even though $X$ may have $64$, $32$ or even $0$ number of lines in it. There are spheres whose existence is not being noticed by $\chi_{top}$ at all. Here let me be vague please. What is going on!?
Any type of editing to make this clearer will be welcome.
References highly appreciated.
 A: This answer addresses the cubic surface case.  It may not tell you anything you don't already know, but just in case:  one way to obtain $X$, which is useful for analyzing the lines,
and also the topology, is as the blow-up of ${\mathbb P}^2$ at six (generically positioned)
points.  
Each point blows up to a ${\mathbb P}^1$, or topologically, an $S^2$, giving the six extra
spheres in $X$ that make the $H^2$ have dimension 7 (1 from the class of a line in
${\mathbb P}^2$, and the rest from the six blow-ups).
Lable the points $P_i$, and the $S^2$s on $X$ obtained by blowing up $E_i$ (for ``exceptional divisor'').
Now the other 21 of the 27 lines are constructed as follows: 
(a) draw lines between distinct pairs of six points (giving 15 lines), and take the proper
transform of each of these.  Here "proper transform'' means the following: if $H_{ij}$ is the line joining $P_i$ and $P_j$ (here $H$ is for "hyperplane'', which in this context
is just a line), we pull-back $H_{ij}$ to $X$, which gives the union of
a line $l_{ij}$ intersecting each of $E_i$ and $E_j$ together with $E_i$ and $E_j$.  Now 
subtract $E_i$ and $E_j$, to obtain just the line $l_{ij}$.
Now in the cohomology ring of $X$, we see that the pull-back of $H_{ij}$ lies in
the ``first'' copy of ${\mathbb Z}$ in ${\mathbb Z}^7$, namely the one coming from
the class of a line in ${\mathbb P}^2$, and so $l_{ij}$ maps to the class which
is $1$ in the first copy of ${\mathbb Z}$, $-1$ in the copies spanned by $E_i$ and
$E_j$, and $0$ in the other copies.  
More succinctly, the cohomology class of $l_{ij}$ is a linear combination of some of
the seven classes we already know.
(b) draw a conic through five of the six points, say all but $P_i$; denote
this $C_i$.  Now take the proper transform of $C_i$; i.e. pull-back $C_i$
to obtain a line $l_i$ together with the five $E_j$ ($j\neq i$), and then subtract
off these five $E_j$.
I have now accounted for 6 + 15  + 6  = 27 lines (the $E_i$, the $l_{ij}$, and the $l_i$)
using just the 7 independent cohomology classes.
Since in the cohomology of ${\mathbb P}^2$ the class of a conic is just twice that
of a line, we see that again the class of $l_i$ is in the span of the known classes,
and we don't get anything beyond the ${\mathbb Z}^7$ we already had.
In the case of a quartic surface, the situation will be similar; if one has a line
$l$ on the surface, the class of this line in cohomology will coincide with some 
(linear combinination of) class(es) that we already know.
A: Even if there is no lines or rational curves, there can still be spheres representing classes in $H^2$. There is no contradiction here since these spheres are maps from $S^2$ to the surface which are not necessarily holomorphic. Some of the spheres may be representable by holomorphic maps. Counting how many in each homology class (sometimes in some generalized sense) is a very interesting problem in enumerative geometry, which is connected to the theory of Mirror Symmetry. 
A: I worry that the other answers may be giving too much detail. What is going on is that there are linear relations between the classes of the lines so that, although they are 27 lines in the cubic surface, the lattice they span in H^2 only has dimension 7. If you want to know exactly how these 27 vectors sit in a 7 dimensional vector space, read Emerton's answer.
A: A few notes.  First off, just because there are spheres doesn't make them lines: conics are spheres as well.  So spheres should morally correspond to rational curves.
In the case of the cubic, all the other lines are linear combinations of the homology classes of any seven! To see this, look at the cubic as the blowup of the plane at six points, then the lines are $\ell_{ij}$, $E_i$ and $C_i$ where $\ell_{ij}$ is the line between two points, $E_i$ is the exceptional divisor over a point, and $C_i$ is the conic missing a point.  Then, if we take $\ell$ to be a line in the plane's proper transform and $E_i$ to be the exceptionals, we can write $\ell_{ij}=\ell-E_i-E_j$ and $C_i=2\ell-\sum_{j\neq i} E_j$.  These equations are technically written in the Picard, but they hold in homology as well.
For the quartic, I have a bit less to say...
