Galina Zapletnuka

Greenhorn
+ Follow
since Mar 11, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Galina Zapletnuka

Hello Anubhav!
Thank you for taking the time to write such a detailed reply. Very helpful.
I will certainly try and make the most of your beginners forum. Thanks.
Don't know if I'm following what you mean, but I originally started playing around with K&B's exercise

class Zippy
{
String[] x;
int[] a[] = {{1,2}, {1}};
Object c = new long[4];
Object[] d = x;
}

and then added some array declarations to see if they work.
Now that you've pointed out the SOP problem, I've put the above code in main and it doesn't compile, because x is unassigned.
Why does it compile without main?
Am I missing out on something? I'm a novice programmer and shy about asking stupid questions, but still?
I see. Thank you very much.
class ArrayFun
{
int[] i = {1,2,3};
System.out.println(i.length);
}

The compiler says:
galina@dell-desktop:~/java training/SCJP$ javac ArrayFun.java
ArrayFun.java:4: <identifier> expected
System.out.println(i.length);
^
ArrayFun.java:4: <identifier> expected
System.out.println(i.length);
^
2 errors
I've tried. The compiler says <identifier> expected.
int[] i = {1,2,3};
System.out.println(i.length);

Why this doesn't compile?
Thanks a lot, guys.
I'm primarily concerned about assigning an uninitialized variable (x) to another varaible (d) and what happens as a result.
I think I got it now
Exercise 7, Chapter 3, K&B book

I don't understand why this compiles:

1. class Zippy {
2. String[] x;
3. int[] a [] = {{1,2}, {1}};
4. Object c = new long[4];
5. Object[] d = x;
6. }

Can anyone explain lines 4&5 please? What does d refer to?

Thanks