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 - Java Tutorial
From the course: Learning Java 11
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…
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
-
-
-
-
-
-
-
-
Classes in Java4m 55s
-
Constructors in Java6m 50s
-
Creating a class in Java3m 57s
-
Creating instances in Java4m 57s
-
Instance methods vs. class methods2m 52s
-
Using instance methods in Java2m 47s
-
Instance and class variables in Java3m 56s
-
Review: Classes vs. instances1m 57s
-
Challenge: Student profile2m 1s
-
Sample solution: Student profile3m 26s
-
-