Welcome back to introduction to Java. This lesson is Java instances, constructors, main functions, and objects. This course is presented by LearnQuest. So instantiation. So when a Java class is built using source code, we clearly add the properties, the functions and we build the code according to how we model that and how it should behave. However, that's the class. The class does not execute. The class is really design time or develop time. It's the object that executes. So an object is declared to be a type of class and this object is built at runtime. So when the object is declared, its assigned a class and it's assigned a name, and behind the scenes, it's assigned different sections of memory because once we name it, it becomes a specific instance of that class. It has all of the properties, methods, functions, attributes of that class. But we can create as many of them as we want and they are all completely stand alone. They actually can be manipulated in different ways but that's more of an advanced topic. So we can see here in instantiation, we actually have this class, car, and it has these private attributes and we see here that it has certain functions associated with it. In the main function, this is where we begin to instantiate them or declare the objects. We can see object car 1. It is a new car class, and notice here we're using this template of the make, the model, and the year. So we'll talk about this, it's called a constructor function. So car 1 is now going to become an object or an instance of the class car. You can see there are others here. So car 1 is not the only one, there's car 2, car 3. They are all cars but they are managing the data such as the make, model, and the year differently and with this particular application, we're hard coding that data in here. Just for an example here of one thing that eclipse does give us is when, after we have declared the car 1 class, if we add the dot operator and click inside here, it will actually go into the car class and it will allow us to pick from this drop down list. If we want to, we can always type it but we can also select here from this list. So we can see here some of the custom methods or functions that we defined and also the attributes that we defined. The constructor. So the constructor is a special function in the Java class. A constructor actually initializes the object at runtime. When we say initializes, it means that it takes the data that we're passing in and it will use that data to actually initialize that object. The constructor can be recognized because it is named the same name as the class. So we have here a class car. Notice here at this time, there's one function also named car and that tells us that it is the constructor and we can see here what data needs to be passed into the constructor. Down here when we're actually declaring the objects, you can see here we are taking the constructor and we're actually passing in real values. You see here a "string" is in quotes and another "string" for model is in quotes, but the year is an integer. The constructor takes the data and uses that data to instantiate the object at runtime. So each of these car objects, car 1, 2 and 3, all three of them are car objects, will have different data and like I said before, different sections of memory on the machine that we're running. So they are completely independent objects. So the constructor can have other forms and a class can have more than one constructor. So we can see here, there are actually in this class car now, there are actually two constructors and their are all named car, and that is allowed it's a special case. However, the header of this function, they have to be different. So we can see here, if we had two public car functions here, it would not be allowed. But notice here we have two strings and an integer for the year but here we only have one string model and one string integer. So when it comes time to instantiate, Java during runtime, will pick the constructor that matches how the constructor is called. So in this case, you can see here where we are passing in the car constructor but we have two strings and an integer or an int. If so, Java is going to go up here and find these two strings and an int and this constructor will be used at runtime. Java selects the constructor based on how it is called in the main function and this is where we are now in the main function. So the main function is where the Java classes are instantiated. So you can see here we have the car classes being instantiated and there are also three other classes, so three new objects being instantiated from an options class. Not only do we instantiate the objects here, but we also build in the business logic and as most everybody knows, our source code is following some business rules or business logic for which the problem that the application is looking to solve for the business value that it's adding. So business logic is here in the main function and this is where the classes are instantiated. While this application is executing here in the main function, the business logic will be executed, the objects will be interacting with one another, or we will be calling different data, so they'll be interacting with the user, or they will be interacting with one another. When we are moving our models, so here's our architectural model, the code, a lot of times the constructors are implicit. So we don't have to add the constructors. We certainly can, but we don't have to. Also, if we eliminate the constructor, Java will call what's called an implicit constructor at runtime. But it is not always necessary to model your constructors. There can certainly be an argument or a disagreement on that but like I said, Java does not require the constructor. So here we covered instantiation, the constructor, the main method or the main function and objects. Please watch the next video where we will introduce the lab. Please complete the lab and please complete the quiz. Thank you.