< Day Day Up > |
Recipe 3.4 Creating a Java Class3.4.1 ProblemYou want to create a new Java class in which to enter code. 3.4.2 SolutionSelect a project and then select File New Class, or right-click a project in the Package Explorer and select New Class. 3.4.3 DiscussionWhen 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 classNote 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.
3.4.3.1 Creating an anonymous inner classIn Eclipse 3.0, code assist (also called content assist) can help when you want to create an anonymous inner class. Place the cursor after the opening brace of a class instance creation and press Ctrl-Space (or select Edit Content Assist). Code assist automatically creates the body of the anonymous inner class, including all the methods you need to implement. Very cool. (For more information on code assist, see Chapter 2.) |
< Day Day Up > |