June 2004
Beginner to intermediate
364 pages
7h 38m
English
You want Eclipse to add a constructor to a class, including a call to the superclass’s constructor.
Select Source→ Add Constructor from Superclass.
For example, if you have this code:
public class DisplayApp { static String text = "No problem."; public static void main(String[] args) { System.out.println(text); } }
and you select Source→ Add Constructor from Superclass, Eclipse will give you this:
public class DisplayApp { static String text = "No problem."; /** * */ public DisplayApp( ) { super( ); // TODO Auto-generated constructor stub } public static void main(String[] args) { System.out.println(text); } }
You also can create constructors automatically when you create a class.
In Eclipse 3.0, you can create a constructor that will assign values to one or more fields. Select Source→ Generate Constructor using Fields, opening the dialog shown in Figure 3-15.
Figure 3-15. Creating a constructor that will fill fields
Selecting the two String
fields,
text
and message
, creates this
constructor:
public DisplayApp(String text, String message) { super( ); this.text = text; this.message = message; }
Chapter 2 of Eclipse (O’Reilly).