• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How vararg works with overriding?

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody explain why i am getting the following?I am getting the answer as "A.m1" as opposed "b.m1",but when i remove the vaar args then i get "b.m1".In the K&B book there is a lot for overload and vararg but not much for overiding.or am i missing something.

[ December 24, 2006: Message edited by: Ravi Nistala ]
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please note that

is not a valid override of

since the parameter types are not same. You are overloading method m1().

Since the method to be called is decided on the reference type, a.m1() calls the method in class A and b.m1() calls the method in class B.

but when i remove the vaar args


You mean the method signature in class A becomes

This causes the method in class B to override the one in class A and by the rules of dynamic dispatch, you get the method in class B getting executed for both the calls.
[ December 25, 2006: Message edited by: Aniket Patil ]
 
Ravi Nistala
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Aniket for the explanation.
 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic