score:0

Accepted answer

its because gettag() is not a static method.

try this

datum dt = datum.heute();
system.out.println(dt.gettag());

score:0

your gettag() method is not static, so you cannot call/invoke that method without an object , that's why you are getting that error.

what you can do is assign a variable to the object returned by datum.heute() and then invoke gettag() on that object

you should do it like this :

datum d  = datum.heute();
system.out.println(d.gettag());

score:0

this line in your code is causing the problem:

system.out.println(datum.gettag());

gettag() method is non-static and cannot be referenced directly in the main method without creating object of datum.

solution:

system.out.println(datum.heute().gettag());

score:0

your heute() method is static and hence the use is proper, but to call the gettag() you need to use the object returned from heute() method.

datum date = datum.heute();
system.out.println(date.gettag());

score:0

if you want to print todays date, you could

public static void main(string[] args) {
    system.out.println( datum.heute().gettag() );
}

datum.heute() is a static (class) method which returns a datum (object) on which you, in turn, can call the non-static datum methods. makes sense? cheers,

score:0

your datum class method gettag() is an instance method, and you are trying to call it with class name, which is not possible because instance methods instantiated after object creation, and only static members instantiated after class load.

so, you have to create an object of your datum class to call gettag() method:

datum d = datum.heute();;
system.out.println(d.gettag());

score:0

you can create an object of the class datum to get non-static access :

public class aufgabe3 {

    public static void main(string[] args) {

        datum datum = new datum()
        system.out.println(datum.gettag());
    }
}

score:0

make an object of your datum class like this in main method. datum datum = new datum(); and then try using datum.gettag();

note:- it is just because you have declared all your variables non-static you can't access them without an object directly using class name(as you are doing right now because they are not declared as static.)

score:0

from your line in exception cannot make a static reference to the non-static method gettag() from the type datum it self say that to you cant not access non-static method directly by class name (like accessin any static method directly by class name), to access non-static method you need reference/object of that class.

create object of your class datum and access method gettag() using that object.

public static void main(string[] args) {
    datum obj = datum.heute();
    system.out.println(obj.gettag());
}  

may this help you.

score:1

i try to answer this question by explaining what your code actually does.

by executing datum.heute(); you make a call to the static method heute() of your datum class. a static method is independent of an actual instance, i.e. an object of that class.

heute() returns an instance of datum, but you never store it anywhere.

then in your second line you try to make a call to datum.gettag(). since you make a call to the class datum and not to an object (which would be somedatumobject.gettag() for example), the java compiler tries to find a static method.

so to solve your aufgabe 3 you need to:

  • create an instance through heute()
  • call gettag() on that object

Related Query

More Query from same tag