If you want to rename a class, you MUST use refactor because there are many dependencies on class names. You can refactor methods, variables, and other things as well. If you go back to the Driver class, you will notice that "p.displayName" was automatically changed to "p.printName":.This is showing you all the places where it will change the "displayName" method to "printName" instead. At the bottom of the IDE, you will notice a Refactoring window has appeared.For the "New Name" field, change it from "displayName" to "printName" and click the "Next" button.Select Refactor > Rename from the menu at the top.Go to the Person class and highlight the "displayName" in the method declaration:.This is simple, but one problem occurs: we have to change every place that called "displayName" as well. We would like to change it to "printName" instead. Lets say we are not happy with the name we gave the method "displayName" in the Person class. Step 4: Using the Netbeans "Refactor" feature If we run our program, we should see the output from our old tutorial and the name "Mike" printed to the console:.All you need to do is add the closing parenthesis and semi-colon. If you press enter, auto-complete will type it automatically for you. You will notice that the method "displayName" is listed as the top one.On the next line, if you type "p.", you will see a list of methods that are available: Now that we have a Person instance, lets see what methods we can call on it.We will just leave the old code from the previous tutorials. In the "main" method of our Driver class, lets create a Person named "Mike". Since we now have the Person class, lets make some use out of it. Step 3: Using intellisense & auto-complete with the classes you create Lets also write a method called "displayName" which will just print the name out.Lets make a constructor that takes a String and sets the name to be that String.Lets give the Person class a member variable called "name".Step 2: Make the Person class do something You should also get a warning at the bottom about putting new classes in the default package. If it is not, please read the note in Tutorial 3, Step 1. Click on the "Finish" button when you are done
0 Comments
Leave a Reply. |