Java Exercise 3: Classes and Methods
class Exam1 { // class = reserved word; Exam = class name (user-defined) int c; // member variable (global); c = variable name; auto-initialized public int add(int a, int b) { // int = return type (integer); (void if no return) // add = user-defined function // a, b = local variables (inside add only) c = a + b; return c; } }Key concepts: member variables vs local variables, return types, method definition.
