What does an example in programming mean?

I do not understand him for a long time. Any alternative word like "instance" that is easier to understand? How not to explain an instance to a non-programmer? an example is similar to an example in the world of normal nations. I can’t understand what it is if I don’t even understand its meaning.

+8
java c ++ javascript
source share
10 answers

"instance" is best understood as referring to a "class" in programming. "Classes" are used to define the properties and behavior of a category of things. For example. The Car class can dictate that all cars are determined by their make, model, year and mileage.

But you cannot specify the specifics of a particular car (for example, 1978 Chevy Impala with 205,000 miles driven by your uncle Mickey) until you create a “copy” of the car. This is an instance that captures detailed information about one particular car.

+11
source share
int main() { int a; //An instance of integer int a,b; //two instances of integer struct1 a; //An instance of struct1 return 0; } 
+4
source share

Here is a pretty standard definition:

An instance in object-oriented programming (OOP) is a specific implementation of any object. An object can vary in a number of ways. Each implemented version of this object is an instance. creating an implemented instance is called an instance.

Every time a program starts, it is an instance of this program. In languages ​​that create objects from classes, an object is an instance of a class. That is, he is a member of this class that set values, not variables. In a non-programming context, you might think of a “dog” as a class, and your dog as an instance of this class.

http://whatis.techtarget.com/definition/instance

Here is a good talk about examples that may help you: https://softwareengineering.stackexchange.com/questions/99202/is-it-called-class-or-object-instance

+2
source share

An object of an object or a link from an object.

+2
source share

To understand what an instance is, we must first understand what a class is.

A class is simply a modeling tool provided by a programming language for use in representing real-world objects in a program or application.

The class is structured to accommodate the properties of an object (member variables) and its operations (functions / member methods).

An instance on the other hand is just a variant of an object created from a class. You create an instance of an object ( Instance ) using a constructor, which is a method in a class specifically defined for this purpose.

Consider a car, if you want to present it in your application, you must define a class, designated as a car, which contains the properties of the car and the operations that the car can perform.

This would look somewhat close to this, assuming it was done in the Java programming language:

 public class Car{ //the properties of the car private String make; private int year; private int gear; private int speed; ... //constructor used to create instances of the car public Car(String carMake, int yearManf){ year = yearManf; make = carMake; } //Car Operation/methods public void setGear(int gearValue){ gear = gearValue } public void applyBrake(int decrement){ speed -= decrement; } public void accelerate(int increment){ speed += increment; } ... } 

Create a car instance: -

 Car BMW = new Car("385 i", 2010); 

BMW is a copy of the car.

+2
source share

An instance is basically an object. In fact, this could mean otherwise. In this case, the English example may mean "To Refer" or "Reference". These instances of objects in programming are also references to source code.

+1
source share

Going beyond the programming world for a second: you know what people are. You are an “instance” of the people class — I can talk about people in general (an object class), or if I have a specific question, I'm talking about an “instance”. An instance may have properties that are not automatically a consequence of class membership. All people have a heart, but not all people have your name and date of birth.

I hope this makes it a little easier?

+1
source share

Instance is a variable which contains the memory address of the object.

+1
source share

In other words, there are patterns for creating things, and there are instances of these patterns.

A class is a template for creating objects. Objects created with it are instances of the class.

 class C { }; C c; // instance of C C d; // instance of C 

A function template is a template for creating functions. Functions created with it are instances of the template. This is usually done implicitly and is called an "implicit instance".

 template <class T> void f(T) { } f(int); // implicit instantiation of f<int> f(double); // implicit instantiation of f<double> 

A class template is a template for creating classes. Classes created with it are instances of the template.

 template <class T> class X { }; X<int> xi; // X<int> is instance of X, xi is instance of X<int> X<double> xd; // X<double> is instance of X, xd is instance of X<double> 
0
source share

with a simple example: we have a project (class) representing a student (object) with fields such as name, age, course (class member). And we have 2 students here, Fu and Bob. So, Foo and Bob are two different instances of the class (Student class) that represent the object (student people).
Credit: Alfreds Computing Weblog

as I understand it, an instance of a pointer to a class object.

ps: I could be wrong.

0
source share

All Articles