课程: Java 8+ Essential Training: Objects and APIs
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Create and use instance methods - Java教程
课程: Java 8+ Essential Training: Objects and APIs
Create and use instance methods
- [Instructor] I've previous described how to use static methods that are called from a class without the class first being instantiated. In this code I have a method named getInput that's defined in the class InputHelper. I call the method from the class itself. I'll take a look at that method by control clicking Windows or command clicking on Mac, and I see that the method has the keyword static, and that's what allows the method to be called in this way, but frequently a method needs to work with persistent data that's stored within an object, then it's known as an instance method, that is a method that belongs to an instance of the class rather than to the class itself. Static methods are marked with the keyword static. Instance methods simply don't have that keyword. So if I delete the keyword static, this method now must be called from an instance of the InputHelper class, not from the class. I'll go back to the main class, and I see that there's now an error indicated, and it's…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
(已锁定)
About encapsulation3 分钟 46 秒
-
Use the Java runtime classes4 分钟 45 秒
-
(已锁定)
Wrap code in static methods5 分钟 56 秒
-
(已锁定)
Declare and use custom classes4 分钟 9 秒
-
(已锁定)
Organize code with packages3 分钟 46 秒
-
(已锁定)
Create and use instance methods2 分钟 27 秒
-
(已锁定)
Manage state with instance variables7 分钟 31 秒
-
(已锁定)
Declare multiple constructor methods5 分钟 2 秒
-
(已锁定)
Use static fields as constants5 分钟 51 秒
-
(已锁定)
Declare and use enum types3 分钟 44 秒
-
(已锁定)
Organize code with nested types4 分钟 15 秒
-
(已锁定)
-
-
-
-
-