From the course: Oracle Java Foundations

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Objects

Objects

(bright upbeat music) - [Instructor] Working with object instances. In the public class ShopApp that you see here, in our main method, we create two customer objects. We instantiate a new customer, and customer01 points to that and we instantiate another customer object and customer02 references that. So we've created two new instances in memory based on the customer class and customer01 is the object reference that's referencing or pointing to that object. Customer02 is referencing or pointing to customer02. We have access fields here, we can say customer01.name = "Duke"; customer02.name = "Marvin"; You'll note by the way that we're not observing the encapsulation in this case, we'll add it a little bit later. We can also call customer01.getName to retrieve the name or customer02.processPayment. In the class customer, you'd have all these different methods that you'd be invoking. Now let's take a look at object instances and the instantiation syntax. The simplest syntax is simply new…

Contents