objects

objects

A object is essentially the instance of a class. So alternatively a class is like the blueprint of a object.A object will have attributes and behaviors, like one would in real life.

A attribute would be like the color, length width and weight of iteam. This is typically represented through the parameters used when making a object( which are passes into the constructor and turned into fields/ global variables).

Behavior is the things the object can do. For example a tea kettle can boil water so a tea kettle object would have a method it could call to boil the water.

Creating a object:

ClassName objectName = new ClassName(<parameter>);

So when creating a object you need to declare what you will call it create the object with the new operator and call the constructer which initializes the object, similar to how you make a variable.

Calling a method:

Variablename = ObjectName.methodName(<parameter>);

Of course you can also declare a variable at the same time as calling the method and of the method is void you don’t set a variable to it.

Calling a field:

Most of the time you should have a get or set method but if you don’t . . .

objectName.varableName

Either in a system.print, parameter or setting a variable.