C++ Classes

The Java class syntax came from C++, so the appearance is very similar, but there are many differences. The syntactic differences are simple to grasp and easy to forget when you're trying to make something compile.

Another difference is that C++ classes do not have to be stored in files by themselves named after the class, though it is sometimes convenient to do so. You may declare your classes where you need them, just as you do with variables.

A more substantial difference is the way objects are stored. In Java, if Fred is a class, the declaration Fred x; creates a reference to an object; the object is not stored in x. In C++, it is; x does not hold reference, but contains the object itself. The consequences of this difference go much deeper than that stupid semicolon you will probably forget the first few times.

And one other difference in practice: Java has a strong convention that class names are capitalized. This is not a requirement of the language, but it is a near-universal practice. Many C++ programmers follow the same convention, but it is by no means universal. In particular, the classes in the standard libraries are generally all lower case.

Another difference is the lack of a universal base class. In Java, all classes implicitly extend class Object, which means they start with a bunch of generic methods. C++ has no universal base class, and you can run all the methods you create yourself.