This is an example of how to use methods in different classes.
Java methods are methods in a class used to perform actions.
They can either be static or public.
Static Methods can be accessed in a class without creating an object.
Below is an example on using a Static Method. I created a class called UsingClassMethods.
public class UsingClassMethods
{
Then I created a static method called testStaticMethod.
static void testStaticMethod()
{
Finally I call the static method testStaticMethod from the main method.
testStaticMethod();
Below is the hole code put together.
public class UsingClassMethods
{
//Since this method is static it can be accessed in this class without creating an object of this class
static void testStaticMethod()
{
System.out.println("This is called from a static method in UsingClassMethods\n");
}
public static void main(String[] args)
{
//This is called from a static method in this class, UsingClassMethods
testStaticMethod();
}
}
For
View original post 295 more words