As a C++ programmer, you
already have the basic idea of object-oriented programming, and the syntax of
Java no doubt looks familiar to you. This makes sense since Java was derived
from C++.
However, there are a surprising
number of differences between
C++ and Java. These differences
are intended to be significant improvements, and if you understand the
differences you’ll see why Java is such a beneficial programming language.
This appendix takes you through the important features that distinguish Java
from C++.
class aType { void aMethod( ) { /* method body */ } }
public class Foo extends Bar { public Foo(String msg) { super(msg); // Calls base constructor } public baz(int i) { // Override super.baz(i); // Calls base method } }
public interface Face { public void smile(); } public class Baz extends Bar implements Face { public void smile( ) { System.out.println("a warm smile"); } }
public void f(Obj b) throws IOException { myresource mr = b.createResource(); try { mr.UseResource(); } catch (MyException e) { // handle my exception } catch (Throwable e) { // handle all other exceptions } finally { mr.dispose(); // special cleanup } }
static final int SIZE = 255; static final int BSIZE = 8 * SIZE;