当前位置:网站首页>重写?重载?你晕了吗?
重写?重载?你晕了吗?
2022-06-22 09:10:00 【C_x_330】
public class CCC {
public static void main(String[] args) {
}
}
class A{
public A foo() {
return this;
}
}
class B extends A {
public A foo(){
return this;
}
}
class C extends B {
public void foo(){}
// 方法名一样,参数列表也一样->不满足重载;方法名一样,返回类型不同,不满足重写->报错
public int foo(){return 1;}
// 方法名一样,参数列表也一样->不满足重载;方法名一样,返回类型不同,不满足重写->报错
public A foo(){return A;}
// 方法名一样,参数列表也一样->不满足重载;方法名一样,返回类型小于等于父类返回类型,满足重写;
// 但是格式错误 应该 return new A();
public A foo(B b){return b;}
// 方法名一样,参数列表不一样->满足重载;参数类型不同,所以不是重写;
}方法重写
重写 要求两同两小一大原则, 方法名相同,
边栏推荐
- Solidity from introduction to practice (II)
- 【详解】神经网络矩阵的点乘与叉乘(pytorch版)
- kali木马入侵win7系统
- 面试突击59:一个表中可以有多个自增列吗?
- Interview shock 59: can there be multiple auto increment columns in a table?
- MSSQL injection of SQL injection
- The third-party libraries commonly used in golang development are not the most complete, but more complete
- How did the Delphi labs, the master of economic models behind axie and Luna, come into being?
- 12 yuan sharing mode
- Message Oriented Middleware (message queue)
猜你喜欢

VMware安装Kali

Node cannot recognize the 'node' entry as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is correc

项目优化+上线(掌握了么?)

【目标检测】|检测错误机制 Why Object Detectors Fail: Investigating the Influence of the Dataset
![[tensorboard] step on all minefields and solve all your problems](/img/35/fc0f7ed311bf7c0321e1257ff6a1a6.png)
[tensorboard] step on all minefields and solve all your problems

Threejs implementation of simple panoramic view demo

User insight into the video industry in January 2022: active users began to pick up under the influence of holidays

14 responsibility chain mode

10 decoration mode

Interview shock 59: can there be multiple auto increment columns in a table?
随机推荐
Volumedetect of ffmpeg
Summary of key knowledge of induction motor in Electrical Engineering (reflected in existing topics)
PHP login registration page
DOM programming
Summary of microexpression data set (full)
Nouvelle éclosion de Coronavirus
MSSQL injection of SQL injection
Ten ways to write ABC by three different threads [concurrent programming JUC]
Flask blog practice - integrated rich text editor quill
Flask blog practice - user management
Sound and shadow 2022 heavy release! Detailed explanation of the new functions of Huisheng Huiying 2022
Kali Trojan invades win7 system
Spark yard memory resource calculation and analysis (Reference) -- optimized configuration of executor cores, nums and memory
【node】脚手架搭建服务器,完成token验证
Php+mysqli create a table, read multiple items, add, modify and query a complete instance
Detailed explanation and Simulation of string and memory operation functions
np. Arange and np Linspace nuances (data overflow problem)
The version problem caused "unable to locate the program input point openssl\u sk\new\u reserve in the dynamic link library c:\users... \libssl-1\u 1-x64.dll"
PIP3 install XXX reports an error: command'lsb_ release -a' returned non-zero exit status 1.
电机学感应电动机重点知识总结(现有题目中反映的)