Object-Oriented Programming: Object-oriented is the basic design idea of Java language, and class is the most basic content in Java. Object-oriented thinking is based on a set of theoretical system, using encapsulation, inheritance, polymorphism and other methods to achieve code reuse, reduce program errors, and thus reduce the workload of software development. 1: Class classes are the basis of the Java language, and any operations are done in the class, such as methods, constructors, parameters, and so on. The class is a template defined in Java. General form of the class:classclass Name {type variable name; ... Type method Name (parameter) {method content;}} The modifier that can be used when declaring a class:/ c3>Private(visible only in this class); protected(visible in this class or in the same package); Public(any class is visible); The modifier that can be used when declaring a variable by default (visible in this class or in the same package):Private(visible only in this class); When declaring a method, it can be decorated with void depending on the return type; The Main method: the entry for the program. The format is as follows: Public Static voidMain (string[] args) {} Construction method: When creating an object in a program, you need to clear or modify the value of its properties to erase the previous operation data , the parameters are initialized with a constructor method. Class does not provide its own constructor, and at compile time, the compiler adds a constructor method to the class. The name of the constructed method must be the same as the name of the class, and there is no return value. The construction method must be positioned at the beginning of the method. The result of initialization is that the number variable is all set to 0, the Boolean type value is False, and the object variable is null; The construction method can take parameters, if you do not want to initialize the properties in the class, add parameters, and pass the values to the individual properties by means of a parameter construction method. The constructor method can have more than one parameter, but the order or number of parameters cannot be the same as the method name. Member variables: A method in a class that is defined, shared, or used in a class can use member variables. Member variables are also called global variables. Syntax: variable modifier type variable name, where the type can be any data type, or it can be an array or a class. In a class, member variables are unique, but the name of the member variable can be the same as the class name. Variable modifiers can use the private,protected、 Public、defaultyou can also use static, a variable used in a static method must be decorated with static, and the final keyword can be used, so that the variable becomes a constant and is not allowed to be modified once it is assigned. Local variables: defined and used in a method, the scope of use is limited to the declared method. Variable names defined in different methods can be the same, and the types of variables may be different. This keyword: Use this to reference member variables and methods without objects. This is optional, but this is important if the member variable and the parameter name in the method are the same. 2: Object Creation Object: Class Name Object name=Newclass name (parameter column); Access to object properties and methods: By adding after the object entity"."to invoke the accessible properties and methods defined in the class, and to compare objects: Use the=="Determines whether the two are the same object, whether the address in memory is the same, the equal method to compare, is the content of the comparison, the value of the same line. Destroyed objects: System.GC (); Java has a garbage collection mechanism that programmers can not consider.
Java-Object-oriented