From the course: Learning Java 11

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Instance and class variables in Java

Instance and class variables in Java - Java Tutorial

From the course: Learning Java 11

Instance and class variables in Java

- [Instructor] With the findArea call we've used the dot-operator to access a behavior or method from our Triangle class. What about attributes? So far, we have only accessed a triangle's instances values using the this keyword inside it's class. But, we can also access it outside it's class. In our main method we could print out triangle A's, Sidelenthree with system.out.printLn, trianglea, sideLenThree. We use the .operator on trianglea, to access it's instance variable. Or attribute variable, sidelenthree. We could also print out triangleb's base with system.out.println triangleb.base The rule here is that it is a function if it has parens and an attribute if it does not have parens. Sidelenthree and base are both attributes here. So, we do not add any parens. We are accessing a variable, not calling a function. Let's save this and run the program. And, see what we get in the output. The last two values 17 is…

Contents