课程: Java 8+ Essential Training: Objects and APIs
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Manage state with instance variables - Java教程
课程: Java 8+ Essential Training: Objects and APIs
Manage state with instance variables
- [Instructor] Just as with instance methods that belong to an instance of a class, there are also instance variables. A variable that's declared within a method is called a local variable. It's local to that method. So for example in this class InputHelper, I have a variable called scanner. It's an object, it's declared and used within the method and its reference expires when the method is done. In a non-static class, when you declare a variable that's in the class but outside of any methods, that's an instance variable. Like the method, it won't have the keyword static. Now, in this project, I've returned the InputHelper to its static state. That is the getInput method is static and can be called directly from the InputHelper class. And I have a starting Main method here. I'm going to create a new class in my utilities package that I'll call MathHelper. Within the MathHelper class, I'll declare a private variable starting with the keyword private, then the type, which will be int…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
(已锁定)
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 秒
-
(已锁定)
-
-
-
-
-