Results 1 to 5 of 5
Thread: tricky initial value problem
- 10-19-2010, 08:31 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
tricky initial value problem
public class Example
{
private int x; // LINE ALPHA
public void method1( int a)
{
int x; // LINE BETA
...
...
...
}
}
What is the intial value of x on LINE ALPHA
What is the initial value of x on LINE BETA
my guess is that they're both ZERO
but I feel like my teacher is tricking me!!!Last edited by Black_Eye; 10-19-2010 at 08:33 AM.
- 10-19-2010, 08:38 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Nope, the first x is initialized to 0 (zero) unless you initialize it to something else; the second x is a local variable and local variables aren't automatically initialized; you have to do it yourself (or assign a value to it before you use that value of that x).
kind regards,
Jos
- 10-19-2010, 08:45 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
?? there should be an answer to LINE BETA
- 10-19-2010, 08:45 AM #4
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
is the answer: local variable not initialized?
- 10-19-2010, 09:02 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Initial capacity of ArrayList
By bugger in forum New To JavaReplies: 12Last Post: 12-30-2009, 08:16 AM -
How to set the designer initial properties when making web report
By freezea in forum Reviews / AdvertisingReplies: 0Last Post: 06-04-2009, 04:25 PM -
Tricky but very interesting problem
By ravjot28 in forum New To JavaReplies: 4Last Post: 06-26-2008, 01:43 PM -
tricky indexOf implementation -- Help!!
By definewebsites in forum New To JavaReplies: 3Last Post: 12-10-2007, 12:48 AM -
Initial SessionFactory creation failed
By escit in forum JDBCReplies: 1Last Post: 08-13-2007, 03:46 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks