The error I get is:
aTyp0eName.java:18: incompatible types
found: void
required: int
df.i = t.increment();
df.i is an int and so is t.increment [fault?]. I'm guessing it's because increment() is void?
Eeeexactly, your guess is correct.
This is the error message explained line by line:
aTyp0eName.java:18: incompatible types
You are trying to assign "void" to an int in line 18.
df.i = t.increment();
Here is where the error is.
found: void
You declare what's the return type in the method "signature".
The method signature is :
<access modifiers> <return type> <method name> (<parameters> )
static void increment ()
So the return type is void.
Next line:
required: int
df.i is int as you have previously stated.
So, pretty much you have already your own question answered.
The good point of having a compiler is that it tells you when something is wrong.
The bad thing ( for humans ) you have to learn to read those messages. They vary from programming language to another and even from compiler to compiler.
This would be a corrected version:
class StaticTest {
static int i = 47;
}
class Incrementable {
static int increment() {
return ++StaticTest.i;
}
}
class DataOnly {
int i;
double d;
boolean b;
public static void main (String[] args) {
Incrementable t = new Incrementable();
DataOnly df = new DataOnly();
df.i = t.increment();
System.out.println(df.i);
}
}
There are some other enhancements could be done, such as adding access modifiers to the methods and attributes, but for now I think this would help.