Javase_1 Basic Concepts

Source: Internet
Author: User

  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 major components: properties and methods. Attributes are generally represented by nouns, and methods are generally expressed by verbs.

  3. If multiple classes are defined in a Java source file, there can be at most one class in the class that is public, in other words, multiple 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 overloads (Overload). Indicates that two or more methods have the same name, but the method parameters are different. The method parameter has two layers meaning: 1) The number of parameters is different. 2) parameter types are different. Note: The return value of the method has no effect on overloading.

  6. Constructor method overloading: Just look at the parameters. If you want to invoke another constructor method in a constructor, you can call it by using this (), which 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 (inheritence): Java is single-inheritance, meaning that a class can only inherit from another class (The inherited class is called the parent class, base class, the inherited class is called a subclass), and the 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 parent class. Next, the constructor of the subclass is called, and the object of the child class is generated. "To create an object of a subclass, you first need to generate the object of the parent class, and there is no child class object without the parent class object." For example: Without a father, there is no child ".

  9. Super Keyword: Super represents a reference to a 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:

    1. There is a parent class, and subclasses have

    2. No parent class, subclasses can increase

    3. Parent class, subclasses can change

  12. Considerations for Inheritance

    1. Construction method cannot be inherited

    2. Methods and properties can be inherited

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

    4. 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

    5. The Super keyword must be the first line statement in the construction method.

  13. Method override (Override): Also called overwrite, the subclass is the same as the method return type of the parent class, the method name is the same as the parameter, so we say that the subclass and the method of the parent class constitute 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 run () method of the parent class can be called through Super.run () in the subclass method, where Super.run () does not have to be placed in the first line of the statement, so the parent class object is already constructed and the parent class's run () is called first method or the run () method that calls the subclass first is determined by the logic of the program.

  16. When defining a class, if the class's parent is not explicitly specified, then the class inherits from the Java.lang.Object class (a class provided by 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 "Love Coffee" blog, please be sure to keep this source http://4837471.blog.51cto.com/4827471/1571322

Javase_1 Basic Concepts

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.