I have a class in Java that is used to get the Date. I want to know how to access this class WITHOUT changing it. (The code i in German, but it's just a couple words)
Here is the class that I can't change:
import java.util.Calendar;
public class Datum {
private int tag;
private int monat;
private int jahr;
/**
* Standard Datum 1.1.1970
*/
public Datum() {
this.tag = 1;
this.monat = 1;
this.jahr = 1970;
}
/**
*
* @param tag : tag > 0 und tag <= 31
* @param monat : monat > 0 und monat <= 12
* @param jahr : jahr beliebig
**/
public Datum(int tag, int monat, int jahr) {
assert(tag > 0 && tag <= 31);
assert(monat > 0 && monat <= 12);
this.tag = tag;
this.monat = monat;
this.jahr = jahr;
}
public int getTag() {
return tag;
}
public void setTag(int tag) {
this.tag = tag;
}
public int getMonat() {
return monat;
}
public void setMonat(int monat) {
this.monat = monat;
}
public int getJahr() {
return jahr;
}
public void setJahr(int jahr) {
this.jahr = jahr;
}
public static Datum heute(){
Calendar c = Calendar.getInstance();
return new Datum(c.get(Calendar.DAY_OF_MONTH),(c.get(Calendar.MONTH)+1),c.get(Calendar.YEAR));
}
}
Here is how I tried to get the current Date:
public class Aufgabe3 {
public static void main(String[] args) {
Datum.heute();
System.out.println(Datum.getTag());
}
}
When I try to run the code it says "Cannot make a static reference to the non-static method getTag() from the type Datum". How can I access the Date without changing the class Datum?