Java Learning Note III (Basic idea of object one)

Source: Internet
Author: User

1 Basic ideas of object-oriented programming (OOP)

Object-oriented is to describe the interaction between objects and objects, and the difference between the process-oriented programming: process-oriented programming, first determine the algorithm, and then determine the data structure; OOP is the first to determine the data structure, in determining the operation.

The object has two characteristics: state and behavior; A similar object is defined as a class, and in software it is a template that defines all the States and methods that are common to all objects of a particular kind;

A class is an instance of a class that creates an object's template, an object;

Entry functions and constructors for Class 2

(1) The entry function of the class is defined as public static void main (Sting [] args)

When there is a main () method in a class, executing the command "Java class name" will start the virtual machine to execute the main method in that class.

1) The Public keyword, declaring that the main function is public is telling other classes to access the function.

2) The Static keyword tells the compiler that the main function is a static function. That is, the code in the main function is stored in a static storage area, that is, when the class is defined, the code already exists.

If the main () method does not use the static modifier, then the compilation will be error-free, but if you attempt to execute the program you will get an error indicating that the main () method does not exist. Because the class that contains main ()

is not instantiated (that is, there are no objects of this class), so its main () method does not exist. Using the static modifier means that the method is static and does not need to be instantiated for use.

3) The Void keyword indicates that the return value of main () is untyped.

4) parameter string[] The main function of args is to provide a means for program users to interact with the program in the command line state.

(2) class constructor: Initializes all variables of the class when an object is defined. It has a class with exactly the same name, and the constructor does not return a value.

Constructor Features: 1) The method name of the constructor must be the same as the class name.
2) The constructor method does not have a return type and cannot be defined as void, and the method type is not declared before the method name.
3) The main function of the construction method is to accomplish the initialization of the object, which can pass the parameters that define the object to the domain of the object.
4) The construction method cannot be called by the programmer, but is called by the system.
5) A class can define multiple construction methods, and if a constructor is not defined when the class is defined, the compiled system automatically inserts a parameterless default constructor that does not perform

Any code. The default value for various data types is int-->0;boolean-->false; object-->null;char---> ' + '
6) The construction method can be overloaded, distinguished by the number, type, or order of the parameters.

3 Overloading of Java methods

Generate overloaded Knowledge points:

1), for a function in the same class;

2), this set of functions, the function name is the same (generally recommended function similar functions to do function overloading);

3), the formal parameters are different, including the number of parameters, different types of parameters or the number of parameters and types are not the same;

4), no relationship to the return value type of the function

5), when the function is called, it will automatically match the type and number of parameters, and decide which function to call. This kind of match is imprecise, will find the most accurate, if not the most accurate, will find the times accurate, and so on,

And this match does not need to be called artificially.

Java Learning Note III (Basic idea of object one)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.