...
It's important to note that static methods and variables cannot access non-static methods or variables, because they are not associated with any particular class instance.
...
Static Variable
...
HeaderClass
Code Block | ||
---|---|---|
| ||
/** * @author Kevin Roark * Static Header Class * Class methods for use to generate a program header and footer */ public class HeaderClass { //variable to keep track of the times one of the class methods was called private static int numberTimesUsed = 0; //Static Utility to print a header - take a string argument to display public static String PrintHeader(String pText) { String myReturn = ""; myReturn += PrintLine(); myReturn += pText + "\n"; myReturn += PrintLine(); numberTimesUsed++; return myReturn; } //Static Utility to print a footer public static String PrintFooter() { String myReturn = ""; myReturn += PrintLine(); myReturn += "End of Program\n"; myReturn += PrintLine(); numberTimesUsed++; return myReturn; } //Getter to return Utility Method was used public static int getTimesUsed() { return numberTimesUsed; } //Private Methods to use in the class //Method prints a line of Characters private static String PrintLine() { return "######################################\n"; } }//end of class |
...