From the course: Learning Java 11

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Constructors in Java

Constructors in Java - Java Tutorial

From the course: Learning Java 11

Constructors in Java

- [Instructor] When we were talking about functions in an earlier chapter, we had to define a function in order to call it. Similarly, we have to define a blueprint or class in order to use it. In the last lesson, we defined the Triangle class or triangle blueprint. But we haven't created any triangles yet. We just defined the attributes and behavior of a triangle in a blueprint. In this lesson, we are going to learn how to create individual triangle instances in our program. An instance is an object created from the class blueprint. Just like we make buildings from blueprints in real life we use a class or blueprint to create objects or instances in code. Thinking back to our triangle class, a triangle has a base height and three side lengths. An instance of a triangle, say named triangleA, could have a base 15, height eight, and sides with lengths 15, eight, and 17. Another instance of a triangle could have base three,…

Contents