Pradyut's profileObject Oriented Programm...PhotosBlogListsMore Tools Help

Blog


    February 06

    Calling non-static function from static function

    Java code shows calling non-static function from static function main
     
    code: -
    --------------------------------------------------------------------------------------------------------------------
    public class Main {
       
        /** Creates a new instance of Main */
        /*static Gear obj = new Gear();*/
        public Main() {
        }
       
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            System.out.println("test");
            /*NewClass obj = new NewClass();
           System.out.println (obj.addn(8));*/
           //Gear t =new Gear();
           Main.Gear t =new Main().new Gear();
           //Main t = new Main();
           t.Jam();
        }  
       
        public /*static*/ class Gear
        {
            public void Jam()
            {
                System.out.println("Testing");
            }
        }
    }
    -------------------------------------------------------------------------------------------------------