Creating and Using a Test Class

Classes need to be instantiated as an Object and be called from a Test or Main Class before it can be executed.

Test Classes performs 2 basic tasks:
  • Provide a starting point (main method) for a program
  • Create an Object instance of the class and testing its methods

The Main Method:

The main method is a special method which is recognised by JVM (Java Virtual Machine) as a starting point for every Java program that runs from the Command Line.

Syntax:
public static void main (String args[])
where
public static is the 2 required modifiers
void keyword means the main method doesn't return any value
main is the method identifier name
(String args[]) allows the method to accept values a string of arguments on the Command Line to be used during program runtime

Only 1 main method can exists in a Java program. The array (args) name that the main method accepts can be changed.

0 comments:

Post a Comment