Overloading and Overriding

The terms overloading and overriding are applied to situations in which you have multiple Java methods with the same name. Within a particular class, you can have more than one method with the same name as long as they have different input parameter types. This is described as overloading the method name. To continue the book example, the BookElement class might have methods declared as follows:

public void addText( String txt )
public void addText( String[] lines )

You would say that addText has been overloaded. The Java compiler can distinguish between calls to these two methods because they have different signatures. The number, type, and order of the input parameters plus the method name determine the signature. ...

Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.