java: Override and Overload & Super keywords

https://www.runoob.com/java/java-override-overload.html

Override

Rewriting is the process of rewriting the implementation process of the accessible method of the parent class by the subclass, and neither the return value nor the formal parameters can be changed. That is, the shell remains unchanged, and the core is rewritten!

Overload

A class contains two or more methods with the same name with different starting parameters, which is called method overload

  • In the same class
  • Same method name
  • The parameter list is different (at least one of the number/type/order of the parameters is different), that is, the method signature is different
  • Has nothing to do with method modifiers/return value types/line parameter names

Role: Provide multiple implementation methods of the same function, and decide which method to use according to the parameters passed by the caller

For example:

public Dog () {
    
    
	System.out.println(‘无参的构造方法’);
}

public Dog (String name, int age) {
    
    
	this();
	this.name = name;
	this.age = age;
}

public Dog (String name, int age, String breed) {
    
    
	// 调用另一个构造方法,必须位于第一行
	this(name, age);
	this.breed = breed;
}

If you customize the constructor, the default no-argument constructor is gone

Guess you like

Origin blog.csdn.net/weixin_43972437/article/details/113483355