From the course: Java Object-Oriented Programming
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Using concrete instances for application logic - Java Tutorial
From the course: Java Object-Oriented Programming
Using concrete instances for application logic
- [Instructor] With our first tree created in code we can begin to write out some application logic. Let's create a program that prints a message if the tree is taller than a 100 feet. All right if then access the height of the oak tree. And if it's greater than 100 feet we'll print out a message. We say my favorite oak tree is an instance of the tree class. It was created from the tree class using the tree constructor and it has all of the attributes and behaviors of a tree. Let's create another tree instance. This tree will be a little shorter and a little wider and it will be a maple tree. Then we'll add logic to print out if that tree is tall. My favorite maple tree, we can access that height attribute again and print out the message if it's tall. Now, it might be hard to tell between the two print statements in the console. So let's add the tree type to the message. While we could hard-code oak and maple directly into the string. Let's dynamically use the instance to resolve 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
-
-
-
(Locked)
Using classes as blueprints4m
-
(Locked)
Building objects with a constructor2m 48s
-
(Locked)
Using concrete instances for application logic4m 32s
-
(Locked)
Understanding the difference between class and instance members4m 54s
-
(Locked)
Exploring a built-in Java class4m 5s
-
(Locked)
Challenge: Build an employee class1m 8s
-
(Locked)
Solution: Build an employee class3m 11s
-
(Locked)
-
-
-
-
-