I wanted to post a real world example I just finished up:
background - I hibernate tools to generate the mappings for my database, a database I am changing as I develop. I change the database schema, push the changes and then run hibernate tools to generate the java code. All is well and good until I want to add methods to those mapped entities. If I modify the generated files, they will be overwritten every time I make a change to the database. So I extend the generated classes like this:
package com.foo.entities.customclass User extends com.foo.entities.User{ public Integer getSomething(){ return super.getSomething(); } public void setSomething(Integer something){ something+=1; super.setSomething(something); }}
What I did above is override the existing methods on the super class with my new functionality (something+1) without ever touching the base class. Same scenario if you wrote a class a year ago and want to go to version 2 without changing your base classes (testing nightmare). hope that helps.