课程: Java Essential Training: Syntax and Structure
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Code Solution: Create a car object - Java教程
课程: Java Essential Training: Syntax and Structure
Code Solution: Create a car object
(upbeat music) - [Instructor] In this challenge, your task is to build a car. You were provided with the car class, which serves as a blueprint containing the attributes of a car. In the buildsCar method, this method accepts details about a specific car, allowing you to construct an instance of the car class. In fact, let's go ahead and do that now. So we create an object of type car, and we can name it Car as well. And to create an instance of the car class, we'll use the new keyword, and we'll call the car constructor, which accepts the make and the model. So now we have a car, and we have the make and the model specified. However, we also need to include the year and the color. We can do that by calling the car setter methods. So we can say car.setYear, and we'll pass in the year, and then car.setColor, and we'll pass in the color. Finally, we'll go ahead and return the car object. And let's go ahead and test this. Great, it worked.
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
-
-
(已锁定)
Defining classes for objects5 分钟 22 秒
-
(已锁定)
Constructors3 分钟 7 秒
-
(已锁定)
Instantiating objects4 分钟
-
(已锁定)
Objects as method parameters2 分钟 9 秒
-
(已锁定)
Objects as method return types1 分钟 55 秒
-
(已锁定)
Wrapper classes1 分钟 54 秒
-
(已锁定)
Records1 分钟 51 秒
-
(已锁定)
Code Solution: Create a car object1 分钟 12 秒
-
(已锁定)
-
-
-