课程: Java Object-Oriented Programming

今天就学习课程吧!

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

Using classes as blueprints

Using classes as blueprints

- [Instructor] Almost anything in real life can be represented in code, but how well something is represented is up to us in what we decide to program. Classes in Java give us a way to model or represent physical objects in code via a blueprint. A blueprint, or class, contains a set of attributes and behaviors that define an object. Let's design a tree object in code using a class. The attributes might be height, trunk diameter, and maybe even tree type. Every tree has these properties or attributes, but their values might not be the same. That's what makes this Class a blueprint. It contains the definition of what a Class should be. As for the behaviors, growing could be a behavior for the tree. It's an action that the tree takes, rather than an attribute representing the current state of the tree. Let's create a blueprint for a tree using a Class in Java. I'm on a Mac, so I'll go ctrl click, and this will allow me to create a new Java Class. We'll call this Tree. And our IDE sets up…

内容