Results 1 to 5 of 5
Thread: Assigning values to an object
- 04-05-2009, 03:50 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 4
- Rep Power
- 0
Assigning values to an object
Hi, I am supposed to have a constructor that creates a new Triangle object, and assigns coordinates and measurements for the triangle.
Here is what I have:
Java Code:public Triangle(int xPos, int yPos, int height, int width) { this(); Triangle aTriangle = new Triangle(); }
Last edited by camper2; 04-05-2009 at 03:55 AM.
-
1) Don't try to construct aTriangle within Triangle's constructor. The constructor itself is already creating a new Triangle object. In other words, get rid of the line:
Java Code:Triangle aTriangle = new Triangle();
Java Code:public class Fubar2 { private int value; public Fubar2(int value) { this.value = value; } }
- 04-05-2009, 04:05 AM #3
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 13
Triangle is clearly not doing anything with the parameters it takes in. That's why it does nothing. You should have something more like
Java Code:this.xPos = xPos; this.yPos = yPos; this.height = height; this.width = width;
- 04-05-2009, 04:06 AM #4
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 13
you beat me, i'm too slow...
- 04-05-2009, 04:13 AM #5
Member
- Join Date
- Mar 2009
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
passing object as value for checkbox values??
By Pooja Deshpande in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-17-2009, 12:55 PM -
declaring fields without assigning values to them
By diggitydoggz in forum New To JavaReplies: 12Last Post: 01-03-2009, 09:22 PM -
Need help in getting values from request object
By nn12 in forum New To JavaReplies: 0Last Post: 11-21-2008, 09:17 AM -
[SOLVED] Creating List of Values Using ClipBoard Object
By Judoon_Platoon in forum Java AppletsReplies: 2Last Post: 05-21-2008, 09:07 AM -
problems with assigning a value to object session
By osval in forum New To JavaReplies: 1Last Post: 08-07-2007, 12:10 AM
Bookmarks