Kann mir jemand sagen wann this. und wann Katze. verwendet wird um Variablen aufzurufen?
Wann this und wann Klasse?
In der Diskussion
Du musst angemeldet sein, um einen Kommentar schreiben zu können
13 November 2021, 22:47
A class is considered to be the blueprints of objects that are later created from it. The class Katze may contain static variables. But static variables are not part of this blueprint! So they will not be part of the future objects. We call them class variables. All object can use them in common. They should be accessed like this, e.g.: Katze.somethingStaticVariable The class Katze can contain non-static variables. Also known as instance variables. Each Katze object will have one of these instance variables of its own. e.g: katze1.age katze2.age katze3.age etc. These age variables are the age variables of three different Katze objects - probably with different values. The Katze class may also contain non-static methods. Also known as instance method. Each Katze object will have such a method of its own. Only within this instance method, it makes sense to use the word "this" if you want to refer to the current object. "this" = the object that is currently using the method.