Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 628 Bytes

instance_methods.md

File metadata and controls

23 lines (17 loc) · 628 Bytes

Instance Methods

In addition to having fields, classes can also have their own method definitions.

These look the same as the method definitions you've seen so far, they are just put within a class definition.1

class Muppet {
    String name;

    void freakOut() {
        System.out.println("**ANGRY KERMIT NOISES**")
    }
}

We call these instance methods because you need an instance of the class in order to call the method.

Footnotes

  1. If you haven't seen the muppets this might have go over your head, but Kermit randomly gets really mad.