Learning Java/Objects and Classes: Difference between revisions
Content deleted Content added
Line 170:
First you must declare an object reference, like this:
<pre>
SomeClass
</pre>
Now, you must initialize it so that it points to an object, like this:
<pre>
</pre>
The '''new''' operation will allocate the memory of an object of type '''SomeClass''' and call the class's '''constructor''' to initialize that memory. For the 2nd class you created, we can make a constructor and remove the main:
Line 180:
public class Operation
{
String message = "Message";
public Operation(String mess)
Line 200:
We can also do it all on one line:
<pre>
Operation op = new Operation("STRINGHERE");
</pre>
This is just like "int i=100", except that we are calling the constructor rather than using a primitive type.
|