Java question

  • 16
    Posts
    14
    Years
    • Seen Mar 26, 2011
    hey if any of you guys are good in java here, i need some help.. i wanna know if this would work but i do not have any access to a compiler so here is the class:
    Code:
    public class LOL
    {
        public static LOL LOL;
        public static void main(String[] args)
        {
            LOL = new LOL();
            LOL.LOL.LOL.LOL.LOL.LOL.LOL.LOL.LOL.LOL.LOL.LOL = LOL;
        }
    }
    it should work right?
    this is just for fun.... these are the things i think about when i am really bored at school
     
    Why don't you have access to a compiler? Just install the JDK.
     
    Oh my, you're messing me up with that xD. Anyway, I tried it and it compiles fine.

    Mind to explain the logic? I'm a bit confused since the instance variable is of type "itself". This is what I think I understand :P:

    public class LOL //Creates a new object class named LOL.
    {
    public static LOL LOL; //Prepares an instance variable of type LOL named LOL.
    public static void main(String[] args)
    {
    LOL = new LOL(); //Creates that same variable.
    LOL.LOL.LOL.LOL.LOL.LOL.LOL.LOL.LOL.LOL.LOL.LOL = LOL; // Gets the static object of type LOL and gets itself inside itself (?? confusion) and assigns it the new variable LOL created just above.
    }
    }
    and it's the same as this which is a bit easier to read:
    Code:
    public class LOL
    {
        public static LOL lol;
        public static void main(String[] args)
        {
            lol= new LOL();
            LOL.lol.lol.lol.lol.lol = lol;
        }
    }
    Eek too many lols!!! I feel like the class LOL can dive infinitely inside itself since it's instance variable is of type itself but why isn't that creating an infinite loop?
     
    Back
    Top