课程: Java Object-Oriented Programming

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Using concrete instances for application logic

Using concrete instances for application logic - Java教程

课程: 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…

内容