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 - 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…
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)
Solution: Bank account balance1m 19s
-
(Locked)
-