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.
Using instance methods in Java - Java Tutorial
From the course: Learning Java 11
Using instance methods in Java
- [Instructor] Let's get back to our triangle program. We've created two triangles, and we are using the dot operator on triangleA to access the findArea function, so that we can find the area of triangleA. Let's add a break point when we make the findArea function call, and then on the first line of the findArea implementation. Now, let's run in debug mode. We are about to call the findArea method on triangleA. In the variables window, we can see that our triangleA instance is there, with its specific attribute values, and the triangleB instance is there, with its specific attribute values. We'll hit continue, and now we find ourselves in the findArea implementation. For triangleA, the base attribute has the value eight, and the height attribute has the value 15. We used the this keyword to access triangleA's specific base and height values, and used the base and height divided by two formula to calculate triangleA's specific area. Hitting continue, and switching over to the console,…
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)
Challenge: Student profile2m 1s
-
(Locked)
Sample solution: Student profile3m 26s
-
(Locked)
-