当前位置:网站首页>冒牌构造函数???
冒牌构造函数???
2022-06-27 08:27:00 【C_x_330】
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)
}
}
尝试编译以下程序会产生怎么样的结果?()
编译错误将发生在(1),因为构造函数不能指定返回值编译错误将发生在(2),因为该类没有默认构造函数
编译错误将在(3)处发生,因为该类没有构造函数,该构造函数接受一个int类型的参数
该程序将正确编译和执行
答案为第三句
注意:这个public void MyClass(long p)可不是一个构造方法!!!仅仅是一个返回值类型为void的普通方法,一i的那个要记住构造函数的格式
public(或者其他访问修饰符) 类名(参数可有可无){}
边栏推荐
猜你喜欢

Helix QAC is updated to 2022.1 and will continue to provide high standard compliance coverage

Redis主从复制以及哨兵模式

Rough reading DS transunet: dual swing transformer u-net for medical image segmentation

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

Lvgl usage demo and instructions 2

数字IC-1.9 吃透通信协议中状态机的代码编写套路

LVGL GUI GUIDER移植代码到STM32

JVM常见的垃圾收集器

游戏资产复用:更快找到所需游戏资产的新方法

Coggle 30 days of ML July competition learning
随机推荐
我大抵是卷上瘾了,横竖睡不着!竟让一个Bug,搞我两次!
关于放大器失真的原因你了解多少呢?
ACM course term summary
05 observer mode
RockerMQ消息发送模式
SPARQL basic introductory exercise
MySQL锁详解
Order by injection of SQL injection
【每日一练】产品卡片动画效果的实现
L'enquête en aveugle a montré que les femmes étaient meilleures que les hommes.
Redis transactions
Redis五种基本类型
orthofinder直系同源蛋白分析及结果处理
[batch dos-cmd command - summary and summary] - map folder to virtual disk - subst
八大误区,逐个击破(终篇):云难以扩展、定制性差,还会让管理员失去控制权?
The 6th Blue Bridge Cup
Closure problem
Eight misunderstandings, broken one by one (final): the cloud is difficult to expand, the customization is poor, and the administrator will lose control?
關聯GIS:條條道路通UE5城
sql注入之order by注入