• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Java question

  • 16
    Posts
    13
    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
     

    Zayin

    #1 Team Rocket fan
  • 705
    Posts
    13
    Years
    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