From the course: Learning Java 11

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating instances in Java

Creating instances in Java - Java Tutorial

From the course: Learning Java 11

Start my 1-month free trial

Creating instances in Java

[Narrator] Let's make some triangle instances. Continuing on our program from the last lesson, we'll move back to our main class, with the main method, in order to do this. We could add a main method to our triangle class, and run that file instead of this file, but I find the separation of our blueprints and the code we are actually running makes it a bit easier to understand at first. To create a triangle, we'll create a triangle variable and call the constructor method. We'll name the first triangle triangle A and give it the values 15, 8, 15, 8, and 17. The second triangle we'll call triangle B and give it the values 3, 2.598, 3, 3, and 30. Now we have two triangle instances. Let's add some breakpoints and walk through this program so we can wee what's going on behind the scenes. We'll add a breakpoint just before triangle A is created, as well as a breakpoint before triangle B is created. Going back to the triangle class, we'll also add a breakpoint on this first line of the…

Contents