The first class foo;is called forward declaration of class foo. It just lets the compiler know that it exists and what it calls the class. This makes foo what is called an "incomplete type" (if the full declaration of foo has not already been noticed). With an incomplete type, you can declare pointers of this type, but you cannot select instances of this type or do anything that requires knowing its size or members.
, , , . , ++ ; Java , Java . , , ; , , , (.. ), , , .
, , , , , ; , , , , .