extends
extends an already existing class with custom methods
package myclass.mydate; import java.util.Date; /* * extends Date = extends class java.util.Date * java.util.Date must be importet */ public class MyDate extends Date { public int getFullYear() { return this.getYear() + 1900; } // overrride the method getMonth from java.util.Date @Override public int getMonth() { return 99; } }
package xmascalc; import myclasses.mydate.MyDate; // import the class MyDate public class XmasCalc{ /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here MyDate my = new MyDate(); int year = my.getFullYear(); System.out.println(year); int month = my.getMonth(); System.out.println(month); } }
2013 99