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

Using instance methods in Java - Java Tutorial

From the course: Learning Java 11

Start my 1-month free trial

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,…

Contents