- Applying the same method to different objects is one of the main concepts behind object-oriented programming.
- The unique existence of a class is an instance of an operation appellation method that executes on an instance. In some cases, a method can be applied to an instance of a class or to the class itself.
- Objects are unique representations of classes, each containing information (data) that is typically private to the object. Methods can provide the means to access and change these data. Object usage methods can affect the state of an object.
- The instance method always has direct access to his instance variable, however, the class method cannot, because he only processes itself, and does not handle any class instances.
class method and instance method: The beginning of the minus sign (﹣) notifies the compiler that the method is an instance method. There is only one alternative, the plus sign (﹢), which represents the class method. A class method is a method that performs some action on the class itself, such as creating a new instance of a class. Instance methods can perform operations on instances of a class, such as setting values, retrieving values and displaying values, and so on.
@interface (Interface section): A method for describing classes and classes, or declaring instance variables for a class.
@inplementation (Implementation part): Used to describe data (the data stored by an instance variable of a class object) and to implement the actual code that declares the method in the interface. You can also add instance variables.
Return value: When declaring a new method, you must tell the compiler whether the method has a return value, or a value of that type if there is a return value. To do this, you need to put the return type inside the parentheses at the beginning of the minus sign or after a plus. If the method does not return a value, it can be declared with the void type.
syntax diagram → &NBS P ﹣ (void) setnumerator &NBSP ; : (int) &NB Sp number;
, &NB Sp ↑  &NBSP, ↑ ↑ & nbsp ↑ &N Bsp ↑ ↑
Method type return type method name method has parameter parameter type parameter name
Set Value method and value method :
- The method of setting an instance variable is generally referred to as the Set value method (setter), whereas the method used to retrieve the instance variable is collectively the method of accessor (getter). The method of setting the value and the method of taking the value are often called accessor (accessor) methods.
- The Set value method does not return any value because its primary purpose is to set the method parameter to the value of the corresponding instance variable. In this case, the return value is not required. Instead, the purpose of the value method is to get the value of the instance variable stored in the object and send it through the program return. To do this, the value method must return the value of the instance as a return parameter.
- You cannot directly set or get the value of an instance variable on the outside of the class, but you need to write the set value method and the value method to set or get the value of the instance variable, which is the principle of data encapsulation.
Classes, objects, and methods