3.4. Creating a Java Class
Problem
You want to create a new Java class in which to enter code.
Solution
Select a project and then select File→ New→ Class, or right-click a project in the Package Explorer and select New→ Class.
Discussion
When you select File→ New→ Class or right-click a project in the Package Explorer and select New→ Class, you’ll see the New Java Class dialog, as shown in Figure 3-7.

Figure 3-7. Creating a Java class
Note the options in this dialog. You can specify the name of the package this class should be in (if the package doesn’t exist, it’ll be created). You can set the access modifier for the class, as well as the class’s superclass, which enables you to implement inheritance. You can also specify what interfaces you want the class to implement, as well as a set of method stubs to create: main, a constructor, and inherited abstract methods.
Tip
If you want to enclose one class within another, you can enter the name of the enclosing class in the “Enclosing type” box in the New Java Class dialog. If you right-click the enclosing class in the Package Explorer and select New→ Class, the enclosing class’s name will appear in the “Enclosing type” text box when this dialog opens; however, it won’t be used unless you check the checkbox next to that text box.
Creating an anonymous inner class
In Eclipse 3.0, code assist (also called content assist) can help when you want to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access