Click here to Skip to main content
16,004,587 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
class Welcome {
    public static void main(String args[]) {
        System.out.println(Hello.a);
    }
}

class Hello {
    static int a=10;
    static Hello h=new Hello();

    {
        System.out.println("IB");
    }

    static {
        System.out.println("SB");
    }
}


What I have tried:

I have tried the above program.
Posted
Updated 15-Aug-17 8:40am
v3
Comments
Dave Kreskowiak 15-Aug-17 14:40pm    
OK, so that code will not even compile. If you're asking how to fix it, we really couldn't tell you much because we have no idea what this code is supposed to do.
Kornfeld Eliyahu Peter 15-Aug-17 14:42pm    
It is probably a typo, as the only problem is 'classs' (and I fixed it already)
Dave Kreskowiak 15-Aug-17 15:01pm    
I don't know about that. It looked like a copy and paste job. I had to fix all the formatting to get it readable. Yes, I did notice the "classs", but left it as it was original content from the OP.


1 solution

You have to learn two things:
1. static
2. Using a debugger...
 
Share this answer
 
Comments
CPallini 15-Aug-17 16:24pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900