当前位置:网站首页>Fake constructor???
Fake constructor???
2022-06-27 08:30:00 【C_ x_ three hundred and thirty】
public class MyClass {
long var;
public void MyClass(long param) { var = param; }//(1)
public static void main(String[] args) {
MyClass a, b;
a =new MyClass();//(2)
b =new MyClass(5);//(3)
}
}
What happens when you try to compile the following program ?()
Compilation errors will occur in (1), Because constructors cannot specify return valuesCompilation errors will occur in (2), Because this class has no default constructor
Compilation errors will be in (3) It happened at , Because this class has no constructor , The constructor accepts an int Parameters of type
The program will compile and execute correctly
The answer is the third sentence
Be careful : This public void MyClass(long p) Not a construction method !!! Just a return value of type void General method of , One i Remember the format of the constructor
public( Or other access modifiers ) Class name ( Parameters are optional ){}
边栏推荐
- 【云原生】2.3 Kubernetes 核心实战(上)
- 粗读DS-TransUNet: Dual Swin Transformer U-Net for Medical Image Segmentation
- Mysql事务中MVCC理解超简单
- LVGL GUI GUIDER移植代码到STM32
- oracle用一条sql查出哪些数据不在某个表里
- Recognize the ordering of O (nlogn)
- 關聯GIS:條條道路通UE5城
- 关于放大器失真的原因你了解多少呢?
- Creation process and memory layout of objects at JVM level
- sql注入之order by注入
猜你喜欢
随机推荐
vim 从嫌弃到依赖(20)——global 命令
this,构造器,静态,之间调用,必须搞懂啊!
Etcd tutorial - Chapter 5 etcd etcdctl usage
IO管脚配置和pinctrl驱动
Redis的持久化机制
ZABBIX deployment instructions (server+win client + switch (H3C))
2022.6.26-----leetcode. seven hundred and ten
关联GIS:条条道路通UE5城
Redis五种基本类型
L'enquête en aveugle a montré que les femmes étaient meilleures que les hommes.
MATLAB小技巧(19)矩阵分析--主成分分析
DV scroll board width of datav rotation table component
VIM from dislike to dependence (19) -- substitution
Binary tree structure and heap structure foundation
分析日志.log
The difference between ArrayList and LinkedList
[ 扩散模型(Diffusion Model) ]
Understanding mvcc in MySQL transactions is super simple
Redis master-slave replication and sentinel mode
Helix QAC is updated to 2022.1 and will continue to provide high standard compliance coverage









