Overloading Constructors – Java #56

*Watch copying and pasting the quotation marks, you may have to retype them to avoid an error

I used eclipse so I will separate main file and the class I built the constructor in, each with their own screenshots and source code.

Screenshot Main File, no imports

————–Beginning of Source Code Main File————————

//Programmer:Akinwale Owi
//Company: Dagba Computers
//Program Purpose: Overloading a Constructor

package DagbaSamples;

//Beginning of Class samples DagbaComputers (contains Main)
public class samples_DagbaComputers
//Beginning of Main Function
public static void main(String[] args)
//Test output
System.out.printf(“Programmer: Akinwale Owi”+ “\n”);

//creating a doubleStuffed object
doubleStuffed example = new doubleStuffed();

//No parameter example
System.out.printf(example + “\n”);

//Creating parameter with int object
doubleStuffed numExample = new doubleStuffed(5);

//Printing out numExample to test should be 105
System.out.printf(numExample + “\n”);

//end of main Function

//End of Class samples DagbaComputers (contains Main)

————-End of Source Code Main File——————————–

———————Screenshot doubleStuffed Class——————————

————————-Beginning of doubleStuffed Source Code————————
package DagbaSamples;

//Beginning of public class doubleStuffed
public class doubleStuffed
//Constructor – no parameters
System.out.printf(“Hello” + “\n”);
//End of Constructor – no parameters

//Constructor – int parameter
doubleStuffed (int num1)
//Reading in num1
int x = num1;

//Adding 100 to int x
x = x + 100;

System.out.printf(“x = ” + x + “\n”);
//End of Constructor – int parameter
//end of public class doubleStuffed

————————–End of doubleStuffed Source Code—————————–

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s