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 - 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,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
Classes in Java4m 55s
-
(Locked)
Constructors in Java6m 50s
-
(Locked)
Creating a class in Java3m 57s
-
(Locked)
Creating instances in Java4m 57s
-
(Locked)
Instance methods vs. class methods2m 52s
-
(Locked)
Using instance methods in Java2m 47s
-
(Locked)
Instance and class variables in Java3m 56s
-
(Locked)
Review: Classes vs. instances1m 57s
-
(Locked)
Solution: Bank account balance1m 19s
-
(Locked)
-