Beginning Java Programming: The Object-Oriented Approach Chapter 6 Displaying an Unintialized Object Member

This is the live code sandbox for Beginning Java Programming: The Object-Oriented Approach Chapter 6. This example demonstrates what happens when an object member is displayed without being initialized. The program displays “null” for the value of myPerson.name. Click “Run” to run the example in your browser or edit the code and then click “Run” to run it with your changes.
You can download the complete code for Beginning Java Programming: The Object-Oriented Approach as well to work with it in your own code editor.

Similarly, this program throws a NullPointerException because the object myPerson.job has not been initialized before it is being used.

Finally, unlike the previous two examples, this program works properly because both the JobType object and Person object have been initialized before they are being used.

Return to the complete list of live code sandbox examples for Beginning Java Programming: The Object-Oriented Approach

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *