当前位置:网站首页>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 ){}
边栏推荐
- 直接修改/etc/crontab 文件内容,定时任务不生效
- MATLAB小技巧(18)矩阵分析--熵权法
- DataV轮播表组件dv-scroll-board宽度问题
- IO管脚配置和pinctrl驱动
- The difference between ArrayList and LinkedList
- ZABBIX deployment instructions (server+win client + switch (H3C))
- 力扣84柱状图中最大的矩形
- Redis master-slave replication and sentinel mode
- 多网络设备存在时,如何配置其上网优先级?
- Refer to | the computer cannot access the Internet after the hotspot is turned on in win11
猜你喜欢
SPARQL基础入门练习
MySQL索引详解
Recognize the ordering of O (nlogn)
並發編程JUC的AQS底層源碼
Matlab tips (19) matrix analysis -- principal component analysis
Rough reading DS transunet: dual swing transformer u-net for medical image segmentation
MySQL index details
2022 love analysis · panoramic report of it operation and maintenance manufacturers
Redis的持久化机制
多网络设备存在时,如何配置其上网优先级?
随机推荐
使线程释放锁资源的操作/方法重载一点注意事项
Helix QAC is updated to 2022.1 and will continue to provide high standard compliance coverage
RockerMQ消息发送与消费模式
Helix QAC更新至2022.1版本,将持续提供高标准合规覆盖率
Matlab tips (19) matrix analysis -- principal component analysis
浏览器的markdown插件显示不了图片
[original] typescript string UTF-8 encoding and decoding
DataV轮播表组件dv-scroll-board宽度问题
Binary tree structure and heap structure foundation
Order by injection of SQL injection
2022.6.26-----leetcode. seven hundred and ten
游戏资产复用:更快找到所需游戏资产的新方法
Linux下Redis的安装
ZABBIX deployment instructions (server+win client + switch (H3C))
Persistence mechanism of redis
2022 love analysis · panoramic report of it operation and maintenance manufacturers
MySQL环境变量配置的教程
Index +sql exercise optimization
(note) Anaconda navigator flashback solution
关于el-date-picker点击清空参数变为null的问题