课程: Java Essential Training: Syntax and Structure
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Records
- [Instructor] A Record is a special type of Java class. That is great for simple objects that will only need fields and methods to access those fields. Here is a record that serves as a model for an account. Notice that instead of the word class, we use the word record. Also, the fields are defined in the class declaration within a set of parentheses followed by a set of curly braces. That's it. This simple declaration creates a record with these fields. You don't need to create any getter or setter methods. All of that is done for you under the covers. However, if you want to add additional methods you can do so within the curly braces. Records can be instantiated just like classes. In this example, account is the name of the record and we use the new keyword, then called the constructor, passing in all of the values. Records are immutable. This means at the fields of a record are final and their value cannot be changed…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
-
-
(已锁定)
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 秒
-
(已锁定)
-
-
-