java - my code regarding the simple String display is not showing the required output? -


public class zoo {     public string coolmethod(){         return "wow !! baby..";     }     public static void main(string args[])     {         zoo z=new zoo();         z.coolmethod();     } } 

this simple code display string not showing desired output i.e. in case string "wow !! baby.." .it compiling , executing fine not showing result.

1st way

public class zoo {     public string coolmethod(){         return "wow !! baby..";     }     public static void main(string args[])     {         zoo z=new zoo();        system.out.println(z.coolmethod()) ;     } } 

2nd way

    public class zoo     {         public void coolmethod(){             system.out.println( "wow !! baby..");         }         public static void main(string args[])         {             zoo z=new zoo();             z.coolmethod();     } } 

in coolmethod() method return type string. in order display result of method, have return void or use system.out.print(); . second problem is, not have main method inside class.create new class test put method

    public static void main(string[] args) { moo m = new moo(); m.usemycoolmethod();     } 

Comments