Results 1 to 6 of 6
- 11-01-2011, 10:23 PM #1
Member
- Join Date
- Oct 2011
- Location
- Tromsø
- Posts
- 41
- Rep Power
- 0
Double constructors, with and without array
here is the code i got:
and the error messageJava Code:class test { private final String abc; private final int x; private final int[] y; private final int[] z; public test(String abc, int x){ this.abc = abc; this.x = x; } public test(String abc, int x, int[] z, int[] y) { this.abc = abc; this.x = x; this.z = z; this.y = y; } }
what is wrong with the code and how should it look like ?Java Code:test.java:41: error: variable y might not have been initialized } ^ 1 error Tool completed with exit code 1
- 11-01-2011, 10:41 PM #2
Re: Double constructors, with and without array
The error message tells you exactly what is wrong: variable y might not be initialised. The error occurs on line 41 which you have not posted.
- 11-01-2011, 10:53 PM #3
Member
- Join Date
- Oct 2011
- Location
- Tromsø
- Posts
- 41
- Rep Power
- 0
Re: Double constructors, with and without array
the rest is commented away so that is the whole code. removed all of the comments and still;
Java Code:class test { private final String abc; private final int x; private final int[] y; private final int[] z; public test(String abc, int x){ this.abc = abc; this.x = x; } public test(String abc, int x, int[] z, int[] y) { this.abc = abc; this.x = x; this.z = z; this.y = y; } }if you look at line 10, y is not there, it's one "}" bracket. and the variables at use there is abc, x. not y.Java Code:test.java:10: error: variable y might not have been initialized } ^ 1 error Tool completed with exit code 1
- 11-01-2011, 10:57 PM #4
Re: Double constructors, with and without array
You have declared your variables as final. This means that you can never change the value of those variables. At the end of the first constructor what value will y (and z) have?
- 11-01-2011, 11:01 PM #5
Member
- Join Date
- Oct 2011
- Location
- Tromsø
- Posts
- 41
- Rep Power
- 0
Re: Double constructors, with and without array
shait, removed final and all worked perfectly. got tons of things to learn still.
- 11-01-2011, 11:08 PM #6
Similar Threads
-
Initializing and array of object via their constructors
By aianta in forum New To JavaReplies: 2Last Post: 08-12-2011, 08:48 PM -
Double Array problem
By AlinkaTroll in forum New To JavaReplies: 6Last Post: 05-03-2011, 01:58 AM -
returning double array
By Billaguana in forum New To JavaReplies: 2Last Post: 01-16-2011, 03:59 AM -
Array of 4 bytes to double.
By blind melon in forum Advanced JavaReplies: 4Last Post: 12-08-2010, 11:19 AM -
Array constructors
By StanO in forum New To JavaReplies: 4Last Post: 11-05-2010, 09:01 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks