User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







java:classes:extends
click
to support this page (eg 0,42 € or so) Thanks.

extends

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;
    }    
}

usage of the extended class

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);
 
    }
}

output

  2013
  99
advertising
java/classes/extends.txt · Last modified: 2013/04/26 10:02 by 88.75.157.182

Impressum