tag:blogger.com,1999:blog-8712770457197348465.post6918417983311999028..comments2024-03-29T05:54:46.190-07:00Comments on Javarevisited: Difference between Method Overloading and Overriding in Java?javin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-8712770457197348465.post-14361921819670200142023-04-13T23:39:52.720-07:002023-04-13T23:39:52.720-07:00GOODGOODAb. Salamhttps://www.blogger.com/profile/17884623915017341915noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-42091769406112247562018-03-07T05:12:28.416-08:002018-03-07T05:12:28.416-08:00We can override static method in sub classes but i...We can override static method in sub classes but it actually hides the super class static method.. This concept called method hiding.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-88966057381956641482014-12-03T10:12:24.459-08:002014-12-03T10:12:24.459-08:00I have been asked twice in interviews that I have ...I have been asked twice in interviews that I have attended - What is good about Java and What is Bad about Java ? Could you please throw some light on this ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-7235315511090540302014-11-28T01:51:24.539-08:002014-11-28T01:51:24.539-08:00Hi Javin, There was a question asked to me in one ...Hi Javin, There was a question asked to me in one of the Interviews is- why Overriding method can not throw a broader exception.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-57132956077620415372013-05-17T03:18:26.473-07:002013-05-17T03:18:26.473-07:00overloading.....method name remains the same only ...overloading.....method name remains the same only changes will be in the type or number of arguments<br /><br />eg: public void testmethod()<br /> public void testmethod(int a,int b)<br /><br />overriding .....method name and argument remains the same only the implementation will change<br />for overriding to happen <br />1>inheritance should happen <br />eg:<br /><br />public class test1{<chetanhttp://javarevisited.blogspot.in/noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-56201695959294263902013-05-09T23:55:27.349-07:002013-05-09T23:55:27.349-07:00I was asked in an interview if we can overload pub...I was asked in an interview if we can overload public static void main(String[] args) method?<br />ans: Yes we can.Anonymoushttps://www.blogger.com/profile/00904327601055779611noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-47600102029264196592013-04-13T00:48:46.782-07:002013-04-13T00:48:46.782-07:00@Shweta: Its not overriding as you havent created ...@Shweta: Its not overriding as you havent created any instance and directly calling mytest() from class TestA so it will print "Ok in A" as overriding doesnt come into picture at all.. <br />@Javin: Do let me know if i am wrong :-)Vivek Hingoranihttps://www.blogger.com/profile/01065655402414692963noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-42212062891399849412013-01-08T18:19:36.233-08:002013-01-08T18:19:36.233-08:00Why people compare method overloading to method ov...Why people compare method overloading to method overriding ? I thing both are completely different operations except similarity in name. Comparing overloading vs overriding is like comparing Orange to apples.Vishalnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-76556743063938848622012-09-27T07:00:56.192-07:002012-09-27T07:00:56.192-07:00i m able to override public static method
clas...i m able to override public static method<br /><br /><br /><br />class TestB{<br /> <br /> public static void mytest()<br /> {<br /> System.out.println("ok in B");<br /> }<br />}<br />public class TestA extends TestB{<br /> public static void mytest()<br /> {<br /> System.out.println("ok in A");<br /> }<br /> <br /> public static void main(String args[])<br /> {<br /> shwetanoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-8965958453433101722012-09-10T03:17:57.164-07:002012-09-10T03:17:57.164-07:00Example of method overloading and method overridin...Example of method overloading and method overriding is not clear to me ? Can you please explain why you overloaded createLoan() method ? Its better you put another example of method overloading and overriding which makes more sense and easy to understand.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-4206279935117770532012-08-31T00:34:32.206-07:002012-08-31T00:34:32.206-07:00What is method overloading in Java ?
- multiple me...What is method overloading in Java ?<br />- multiple method with same name<br />Why do you need overloading in Java<br /> -because you have method which does same job but with different operands e.g. size() method finding size of Array, Collection and string<br /><br />When do you use method overloading in Java ?<br />same as above <br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-89879812395364335442012-08-29T22:02:37.351-07:002012-08-29T22:02:37.351-07:00@Rajiv, Thanks for informing about covariant retur...@Rajiv, Thanks for informing about covariant return type, which allows to change return type of overriding method in Java 1.5, does you can do this only on methods which has Object as return type or its also possible to override a method which has return type long with overriding method has return type primitive int ?Sunilnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-10703384421026468522012-08-29T21:59:43.441-07:002012-08-29T21:59:43.441-07:00Most simple difference between overloading and ove...Most simple difference between overloading and overriding in Java is former is a compile time activity while later is a runtime activity. Overloading is fast , overriding is slow. Overloading uses static binding, overriding uses dynamic binding. private, static and final method can be overloaded but can not be overridden.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-88904026260448006212012-08-02T18:25:33.204-07:002012-08-02T18:25:33.204-07:00Overriding method cannot assign weaker access priv...Overriding method cannot assign weaker access privileges: <br />protected in parent<br />must be kept<br />public/protected in subclassAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-86777127529417136562012-07-03T21:03:19.836-07:002012-07-03T21:03:19.836-07:00to add on what you have described, overloading is ...to add on what you have described, overloading is done in two steps, first JVM finds all the methods which are applicable for a given type of argument and than in second step it pick the most specific method. for exmaple if you have two method one which takes Object clas as parameter and other takes String class as parameter like below<br /><br />public void show(Object ob){}<br />public void Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-62149114917767545472012-05-04T05:01:41.900-07:002012-05-04T05:01:41.900-07:00Hi Javin,I visit your blog regularly and I found t...Hi Javin,I visit your blog regularly and I found that you missed covariant return which is added in Java5 in the case of method overriding.<br />When a subclass wants to change the method implementation of an inherited method (an override), the subclass must define a method that matches the inherited<br />version exactly. Or, as of Java 5, you're allowed to change the return type in the<br />Rajeevnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-20604183550589485472012-01-05T03:51:21.226-08:002012-01-05T03:51:21.226-08:00Good point, I have added one section regarding exc...Good point, I have added one section regarding exception handling for overloading and overriding methods in java. thanks for pointing this.Javin @ spring interview questions answershttp://javarevisited.blogspot.com/2011/09/spring-interview-questions-answers-j2ee.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-22063705492007098422012-01-04T19:50:42.115-08:002012-01-04T19:50:42.115-08:00what about the exceptions while overriding and ove...what about the exceptions while overriding and overloadingAnonymousnoreply@blogger.com