Intro. to Programming Workshop - 4

Welcome back to the Intro. to Programming Workshops! This week's workshop will focus on methods!
Latest additions to the base source code for PokeVentures include player walk animations and switching player characters (press 1, 2 or 3).

Resources

Summary

Methods

List of modifiers:

  • public - visible to classes (files) in any package (folders)
  • protected - visible to classes in same package and child classes
  • blank - visible to classes in same package
  • private - visible to same class only
  • static - always available during the program's life
  • final - reference cannot be altered after initialization
  • abstract - to define abstract classes and methods
  • synchronized - (not used in course) for threads
  • volatile - (not used in course) for threads

Syntax:

modifiers return_type methodName(Parameter list) {  
    code_block
}

Example:

public static double square(double a) {  
    double result = a*a;
    return result;
}