Review in-depth understanding of Java object-oriented programming 1

Source: Internet
Author: User

Review in-depth understanding of Java object-oriented programming

  1. A class is an abstract concept in which an object is a concrete representation of a class and is a concrete concept. There is a class first, and then the object is generated by the class. The object is also called an instance (Instance).

  2. A class consists of two components: properties and methods. Attributes are generally represented by nouns, and methods are generally expressed by verbs.

  3. If a Java source file defines multiple classes, at Most one of these classes is public, in other words, many of the classes defined may not be public.

  4. When you pass a method's parameter passing in Java, the parameter is passed uniformly as a pass value (pass by value), regardless of whether the native data type or reference type is passed. There is no concept of pass by reference in Java.

  5. Method overloading (Overload). Indicates that two or more methods have the same name, but the method parameters are different. The method parameter has two meanings: 1) The parameter number is different 2) The parameter type is different. Note: The return value of the method has no effect on overloading.

  6. Overloading of construction methods: Just look at the parameters. If you want to call another constructor method in one of the constructor methods, you can call it by using this (), which in this () bracket represents the parameters of the target constructor method. This () must be used as the first statement of the constructor method, in other words, this () cannot have any executable code before it.

  7. Inheritance (inheritance): Java is single-inheritance, meaning that a class can only inherit from another class. The inherited class is called the parent class or the base class (base class), and the inherited class is called a subclass, and inheritance in Java uses the extends keyword.

  8. When a subclass object is generated, Java defaults to calling the parent class's constructor without arguments, and then executes the constructor, generating the object of the subclass. "To generate the object of a subclass, you first need to generate the object of the parent class, there is no subclass object without the parent object, such as: No father, No child".

  9. Super Keyword: Represents a reference to the parent class object.

  10. If a subclass uses super () to explicitly invoke a constructor of the parent class, it will look for the constructor that corresponds to super () and will not look for the parent class's constructor without arguments. As with this, super must also be the first execution statement of the constructor method, and no other executable statement can be preceded.

  11. About 3 points of inheritance:

    A) There is a parent class, and there are subclasses.

    b) The parent class does not have a subclass that can be incremented.

    c) The parent class has some, subclasses can change.

  12. Considerations for Inheritance

    A) The construction method cannot be inherited.

    b) Methods and properties can be inherited.

    c) The constructor method of the subclass implicitly calls the parent class's constructor without arguments.

    D) When the parent class does not have a constructor method with no arguments, the subclass needs to use super to explicitly call the parent class's constructor, and super refers to a reference to the parent class.

    e) The Super keyword must be the first line statement in the constructor method.

  13. Method Override: The subclass is the same as the method return type of the parent class, with the same method name as the parameter, so that we say that the method of the child class and the parent class constitutes an overriding relationship.

  14. Method overrides the relationship between method overloads: Overloading two or more methods that occur inside the same class. Overrides occur between the parent class and the child class.

  15. When two methods form an overriding relationship, the parent class run () method can be explicitly called in the subclass method through Super.run (), where the Super.run () method does not have to be placed in the first line of the statement, because the parent class object is now constructed. Whether the run () method of the parent class is called first or the run () method that first calls the subclass is determined by the logic of the program.

  16. When defining a class, if the parent class of the class is not explicitly executed, then the class inherits from the Java.lang.Obejct class (a class provided in the JDK, the object class is the direct or indirect parent of all classes in Java).

  17. Polymorphism (polymorphism): We say that a subclass is a parent (a rose is a flower, a man is a man), so polymorphism means that a reference to the parent type can point to the object of the subclass.



This article is from the "Java" blog, so be sure to keep this source http://5737386.blog.51cto.com/5727386/1660993

Review in-depth understanding of Java object-oriented programming 1

Related Article

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.