I am reading the book The Java Programming Language. In the chapter which explains overriding method, it says:
Making an override met
Contract of type (class, interface, enum) is the, well, the contract this type promises to comply to. It states:
addData(float) of MathAverage class which calculates average of it's input may state that every time your call to add(float) is return, you shall expect call to MathAverage.getAverage() to return correct average of current input.Contract is specified in free-form in javadoc of type. There are some tools/practices to enforce execution of contracts, but they are limited, exactly because contract can be arbitrary, or, even, self-contradictory, in case of programmer's error.
Since subtyping(subclassing) can extend/modify behavior of supertype methods in arbitrary way, it may, as well, violate some parts of supertype's contract. Example of this would be extending HashMap, which accepts null values and keys, with some implementation which prohibits null values in calls to it's methods.
Other important aspect about type contract is that subtype can have stronger contract (covering subset of constraints in type's contract), but can't have weaker contract (covering superset of constraints in type's contract).
For example, if your type's method 'doX(n)' promises to take O(n) (linear) time, 'doX(n)' in subtype can take O(1) (constant) time, but can not take O(n^2) time.