Thanks for the replies,
And no, I am not a troll. I do not hang in this newsgroup and am curious
why I would be thought a troll? What in the question would make someone
think that?
My instructor, who is never wrong by the way, specified 8.5. I too have
concluded that it is 8.7. He will jump up and down and scream when you
make a mistake, but he is allowed to make any mistake, but that is
another story...
I have scoured the web and came up with what appears to be a solution.
The code follows. Do the readers of this post think that this is an
acceptable answer to the question posed?
When class BS1 runs, output is: 5
When class BS2 runs, output is: 4
class A {
public static int A = 1 + B.B;
}
class B{
public static int B = 2 + A.A;
}
public class BS1 {
public static void main (String [] args){
int a = A.A;
int b = B.B;
System.out.println (a + b);
}
public class BS2 {
public static void main (String [] args){
int b = B.B;
int a = A.A;
System.out.println (a + b);
}
In article <c1df3i$vfe$>,
says...
> j l wrote:
>
> > I have spent a couple of hours attempting something and have been totally
> > unsuccessful. I was wondering if I could get some assistance on a
> > particular homework problem.
> >
> > Homewok question from the professor.
> >
> > Read JLS section 8.5 on static initializers.
> >
> > Write two programs which produce different output and where the only
> > difference in the programs is in the order of declarations of static
> > variables.
>
> Please note that it is section 8.7 (not 8.5) of the JLS, 2nd Edition,
> that discusses static initializers. Read the section, and pay attention
> to what it says about the order of declarations. As your instructor has
> pointed you to material about static initializers, it is probably safe
> to assume that he or she envisions a solution that makes use of one or
> more of them.
>
> If you don't understand what you have read then post a specific question
> here, or (perhaps better) in comp.lang.java.help. If you have code that
> you think should solve the problem but doesn't, then you could post it
> here or in c.l.j.h and ask for advice.
>
>
> John Bollinger
>
>
>