From the course: Java 8+ Essential Training: Objects and APIs
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Organize code with nested types - Java Tutorial
From the course: Java 8+ Essential Training: Objects and APIs
Organize code with nested types
- So far whenever I've wanted to create a new class or other type in my application, I've defined it in its own file. But you can combine types together in a parent/child relationship within a single file. These are then called nested types, or sometimes member types. Let's take the operation enum that I created in a previous video. Right now it's in its own file, operation.java. But it's obviously clearly related to the MathHelper class. It's only used when you're either calling the MathHelper class or within the MathHelper class' code. So this is an opportunity to reorganize the code and make things a little bit easier to find. I'll start in operation.java, and I'll copy the enum declaration to the clipboard. Then I'll go back to MathHelper.java, I'll place the cursor within the class declaration, but outside of any methods, and I'll paste that code into place. Now operation is a nested enum. It's a nested type of the MathHelper class. I'll come back to operation.java, and I'm going…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
About encapsulation3m 46s
-
Use the Java runtime classes4m 45s
-
(Locked)
Wrap code in static methods5m 56s
-
(Locked)
Declare and use custom classes4m 9s
-
(Locked)
Organize code with packages3m 46s
-
(Locked)
Create and use instance methods2m 27s
-
(Locked)
Manage state with instance variables7m 31s
-
(Locked)
Declare multiple constructor methods5m 2s
-
(Locked)
Use static fields as constants5m 51s
-
(Locked)
Declare and use enum types3m 44s
-
(Locked)
Organize code with nested types4m 15s
-
(Locked)
-
-
-
-
-