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).
A class consists of two major components: properties and methods. Attributes are generally represented by nouns, and methods are generally expressed by verbs.
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.
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.
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.
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.
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.
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 ".
Super Keyword: Super represents a reference to a parent class object.
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.
About 3 points of inheritance:
There is a parent class, and subclasses have
No parent class, subclasses can increase
Parent class, subclasses can change
Considerations for Inheritance
Construction method cannot be inherited
Methods and properties can be inherited
The constructor method of the subclass implicitly calls the parent class's constructor without arguments
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
The Super keyword must be the first line statement in the construction method.
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.
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.
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.
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).
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