Wednesday, June 29, 2011

public static void main Here !!!!!!

Here is the fun time with our JVM main thread.

 
Well we have class called One.java :

public class One {
   
    public static void main(String[] args) {
       
        System.out.println("You are in One");
       
    }
}

Second class Two.java :

public class Two {
   
    public static void main(final String[] args) {
       
        new One().main(args);
       
    }
}

      Though it not good practice, class two.java also Legal. When executing Two.java
you will get “You are in One”.

Now the interesting part, We have class Three.java :

public class Three extends One {
   
    public static void main(final String[] args) {
       
        new Three().main(args);
       
    }
}

      Here the class Three.java extends One.java. Both the classes have main method. 
We all know “Static methods are not eligible for method overriding”. So nothing
inherited here. Now guess the outputof class Three.java….

Is it completely depends on your stack size ???

Itching!!!!!!!!!

I’m stupid again J 

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...