Override Methods In NetBeans IDE
12 April 2007NetBeans has a very rich set of features which allow users to generate code or templates. There are a variety of cases where user can generate code using NetBeans IDE. Here we will discuss an easy way to generate overriding methods in sub classes.
Suppose you have two classes. “Car” and “FourWheeler”.
/* * FourWheeler.java* * Created on April 11, 2007, 10:30 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package javatips; public class FourWheeler { /** Creates a new instance of FourWheeler */ public FourWheeler() { } /** * Holds value of property capacity. */ private int capacity; /** * Getter for property capacity. * @return Value of property capacity. */ public int getCapacity() { return this.capacity; } /** * Setter for property capacity. * @param capacity New value of property capacity. */ public void setCapacity(int capacity) { this.capacity = capacity; } } Car. Java package javatips; public class Car extends FourWheeler{ /** Creates a new instance of Car */ public Car() { } /** * Holds value of property color. */ private String color; /** * Getter for property color. * @return Value of property color. */ public String getColor() { return this.color; } /** * Setter for property color. * @param color New value of property color. */ public void setColor(String color) { this.color = color; } }
Now you want that Car class which extends FourWheeler should override methods of FourWheeler class. Then Follow these steps.
- Select Source - > “Override Methods” or press “Ctrl+I”. You will see following screen.
- On clicking the below screen appears.
- Select the methods you want to override. Code will be automatically generated.
package javatips;public class Car extends FourWheeler{ /** Creates a new instance of Car */ public Car() { } /** * Holds value of property color. */ private String color; /** * Getter for property color. * @return Value of property color. */ public String getColor() { return this.color; } /** * Setter for property color. * @param color New value of property color. */ public void setColor(String color) { this.color = color; } public void setCapacity(int capacity) { super.setCapacity(capacity); } public int getCapacity() { int retValue; retValue = super.getCapacity(); return retValue; } }
Related Posts:
- Introduction to Stateful Session Bean In NetBeans
- Adding Business Methods to an EJB in NetBeans
- How To Add Fields And Generating Getter-Setters
- Generating JavaDoc For a Project In NetBeans IDE
- Calling a Stateful Session bean in NetBeans
- Calling A Session Bean Using A Web Module
- Creating JUnit Test Cases using NetBeans
- Developement Of Enterprise Applications in NetBeans IDE
- Creating J2ee Modules In NetBeans IDE
- Introduction
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Override Methods In NetBeans IDE