|
|
|
|
Top Topics in our Forum';
|
|
|
Constructors In JavaExamples and purpose of Constructors
I must admit that I have a personal bias for using Eclipse and or the command prompt to compile and run Java programs, possibly out of habit or some misplaced sense of how 'real programmers' do things...however, after teaching Java for a year, I have become sold by how well BlueJ and other tools like Jeroo teach CS concepts. For that reason, this entire page on constructors is based on using BlueJ and is aimed at programmers who are using BlueJ to try to better understand constructors and Object Oriented Programming.
Pre-requisites:
After have downloaded and installed BlueJ, you can start working with some pre-created Java Objects that you get with BlueJ. You will need to find the examples folder that will be in the directory you installed BlueJ. If you can't find the examples directory, just download and unzip this link. The Purpose and Role of ConstructorsThe purpose of constructors is to initialize instance variablesLet's see how that is done with Shapes project in the examples folder. Help getting to the shapes project open.
Below is a picture of
the Shapes Project and how we create Circle Objects with BlueJ. Notice that there are four distinct (the technical word is overloaded) Constructors that all do the same thing: Create a circle object.
Experiment with the circles class. Try moving them around making them visible etc... Look at the code for the class.
The only difference between the picture below and the one above is the red arrow. Can you figure out what that red arrow represents?
Top |