søndag 16. september 2012

Java objects and classes

Finally. Some time to play!

As i was reading about objects and classes I was confused. The only way to move beyond the mind fog, was to try it.

That meant installing Eclipse. Again. I've installed it twice before, but this was the first time it made sense. It was also the first time I knew about ctrl+space. And what a difference that made.

Basically, a class can have class and object variables and methods. Those that belong variables and methods that belong to the class are defined with the keyword "static". If "static" is not used, it's an object variable.

public class Class {
public static int classInteger = 0;


Class variables can be accessed by both class and object methods. Objects variables can only be accessed by object methods. Or something like that.

Also: If it's defined with "private", it can only be read and written by methods within the class. So setters and getters would have to be used to alter them.

Etiketter: , , , ,

0 Kommentarer:

Legg inn en kommentar

Abonner på Legg inn kommentarer [Atom]

<< Startsiden