Java Method Overloading

1.You refer to a method by using the name of the method,A method is name name for an action.The same word expresses a number of different meanings---it's overloaded.

2.the method overloading is essential to allow the same name to be used with different argument types.

3.Each overloaded method must take a unique list of argument types,that distinguish the overloaded methods.

4.Why only class names and method argument lists? Why notdistinguish between methods based on their return values? 

    you can also call a method and ignore thereturn value. This is often referred to as calling a method for its side effect, since you don’tcare about the return             value,but instead want the other effects of the method call. So if youcall the method this way:   

   f();

   how can Java determine which f( ) should be called? And how could someone reading thecode see it? Because of this sort of problem, you cannot use return          value  types to distinguish overloaded methods. 

5.When you don't put in any constructors,it's as if the compiler says :" You are bound to need some constructor,so let me make one for you!"

   But if you write a constructor,the compiler says:"You've written a constructor so you know what you're doing,if you didn't put in a default it's because you    meant to leave it out!"

   SO,IF YOU DEFINE ANY CONSTRUCTORS(WITH OR WITHOUT ARGUMENTS),THE COMPILER WILL NOT SYNTHESIZE ONE FOR YOU.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值