[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 745
  • Last Modified:

Call function from another java file

Hi all..

I'm new to java programming and i need your help to solve my problem..

if i have a file hello.java as below,

public class hello
{
  public static void main(String[] args)
  {    //do nothing - this will keep us from getting a compile error
  }

   public static String SayHello(String name)
  {
  return "Hello " + name;
  }
}

how can i call SayHello function from another java file? let's say from file CallFunction.java hehe can i actually do this? can u give me any example?

thankss :)
0
pipinana2002
Asked:
pipinana2002
  • 2
1 Solution
 
yongsingCommented:
Just call hello.SayHello() like this:

public class CallFunction {
  public static void main(String args) {
    hello.SayHello("pipinana2002");
  }
}
0
 
pipinana2002Author Commented:
Hi yongsing.. thanks so much for your reply :)

but why when i want to run the CallFunction.java, I always got this error:

Exception in thread "main" java.lang.NoSuchMethodError: main

hope u can help me.. tks :)
0
 
pipinana2002Author Commented:
hi yongsing..

hehehe i solve the probs already.. tks so much for your help :) hehehe really helps me.. coz i've been looking through the internet n cannot find the answer :)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now