Instance

Updated: 09/12/2023 by Computer Hope

An instance may refer to any of the following:

1. With programming, an instance is one occurrence of a class or object. For example, a program may have a class/object named Animal, but there could be many instances of Animal, such as lion, cat, and dog. An example using JavaScript is shown below, where the Animal object is created, followed by three instances.

function Animal(numlegs, mysound) {
this.legs = numlegs;
this.sound = mysound;
} var lion = new Animal(4,"roar"); var cat = new Animal(4, "meow");
var dog = new Animal(4, "bark");

The Animal object allows the number of legs and the animal's sound to be set by each object instance. In this case, all three instances (lion, cat, and dog) have the same number of legs but make different sounds. This process allows items of similar structure or that perform similar functions to reuse code rather than duplicating it.

2. With MMORPGs (massively-multiplayer online role-playing games), an instance is a location created for a single player or group of players. This process allows players to run through the same content without waiting for another group to finish.

Class, Game terms, Object, Programming terms, Subroutine, Zone