当前位置:网站首页>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 ){}
边栏推荐
猜你喜欢

關聯GIS:條條道路通UE5城

参考 | Win11 开启热点之后电脑不能上网

VIM from dislike to dependence (20) -- global command

Mapping of Taobao virtual product store opening tutorial

Redis五种基本类型

DV scroll board width of datav rotation table component

Reference | upgrade win11 mobile hotspot can not be opened or connected

oracle用一条sql查出哪些数据不在某个表里

MATLAB小技巧(19)矩阵分析--主成分分析

orthofinder直系同源蛋白分析及结果处理
随机推荐
JS EventListener
SIG associé: toutes les routes mènent à ue5
关于放大器失真的原因你了解多少呢?
Analysis of orthofinder lineal homologous proteins and result processing
Refer to | the computer cannot access the Internet after the hotspot is turned on in win11
浏览器的markdown插件显示不了图片
Game asset reuse: a new way to find required game assets faster
MySQL index details
Associated GIS: all roads lead to ue5 City
Rough reading DS transunet: dual swing transformer u-net for medical image segmentation
DataV轮播表组件dv-scroll-board宽度问题
2022.06.26(LC_6100_统计放置房子的方式数)
Pin details in rust
MySQL environment variable configuration tutorial
PayPal账户遭大规模冻结!跨境卖家如何自救?
Rust async: SMOL source code analysis -executor
[11. two dimensional difference]
LVGL GUI GUIDER移植代码到STM32
lvgl使用demo及说明2
[13. number and bit operation of 1 in binary]