Java Object-oriented essentials

Source: Internet
Author: User

1. Object-oriented three major features: inheritance, encapsulation, polymorphism.

2. Class-To-Object relationships: A class is a template for an object that is an instance of a class that can be used by an object.

3. A class is made up of attributes (member variables) and methods (member methods)

4. Object-generated Format: Class Name Object name = new class name;

5. If an object is not instantiated and is directly referenced, a null-pointing exception appears when used;

6. The class belongs to the reference data type, when the reference is passed, the use of the memory is passed;

7. Encapsulation of classes: decorated with the private keyword, the encapsulated property cannot be directly called externally, but only by setter or Getter method. As long as it is an attribute, it must all be encapsulated.

8. The constructor method can be initialized for the properties in the class, the constructor method is the same as the class name, no return value type declaration, if the construction method is not explicitly defined in the class, it will automatically generate a non-parametric construction method of nothing, the construction method in one class can be overloaded, but each class has at least one construction method.

The 9.string class is special in Java, string can be directly assigned to the way, or through the construction method to instantiate, the former only produces an instantiated object, and this instantiation object can be reused, the latter will produce two instantiated objects, emphysema is a garbage space, The Equals () method is used when comparing content in string, and "= =" compares the address values of two strings. The contents of a string cannot be changed once it is declared.

10. Use the This keyword in Java to represent the current object, through the "this. Property" can call the properties in this class, through the "this. method ()" Can call other methods in this class, or through the form of this () to call the constructor method in this class, However, the call is placed on the first line of the construction method.

11. Properties and methods that use the static declaration can be called directly by the class name, and the static property is shared by all objects and can be manipulated by all objects.

12. If you need to restrict the generation of class objects, you can privatize the construction method.

13. The use of an object array is divided into a declaration array and an array that opens up two steps, and the content of each element in the array after space is null.

14. An inner class defines another class within a class, using a private operation that provides easy access to external classes. An inner class declared in a method that wants to access the parameters of a method must precede the parameter with the final keyword.

Java Object-oriented essentials

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.