Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 615 Bytes

invoke_other_methods.md

File metadata and controls

29 lines (23 loc) · 615 Bytes

Invoke Other Methods

Inside of an instance method you can invoke other instance methods on the same class by writing their name and providing any needed arguments.

class Elmo {
    int age;

    void sayHello() {
        System.out.println("Hi, I'm Elmo");
        System.out.print("I am ");
        System.out.print(age);
        System.out.println(" years old.");
    }

    void startTheShow(String showName) {
        sayHello();
        System.out.println("Welcome to " + showName);
    }
}

void main() {
    Elmo elmo = new Elmo();
    elmo.age = 3;

    elmo.startTheShow("Sesame Street");
}