• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

VarArgs

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Why I am getting
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you SHOULD know that for overriding a method, the method arguments SHOULD be same
here you are not overriding the method at all
and about runtime polymorphism, it is applicable only to method overriding

hope this helps:)
 
Saibabaa Pragada
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's right..what I am trying to ask is, At Runtime, I modified the Beta class structure as given below.
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
of course here is runtime polymorphism
the code you have written is confusing yourself only
I modified the code
and see the comments in it

and the runtime polymorphism applies to OVERRIDING methods only
and the method with signature (String a) is not taking part in overriding at all

now you may ask that var-args are chosen at last if the exact method signature is not available
in this case, we have the method with exact signature available
but still the var-args method is chosen due to following reasons
  • Alpha a = new Alpha(); means that reference type is of class Alpha
  • at comile time, there is only one method availabe in class Alpha i.e. var-args method
  • when the compiler sees the call a.foo("test"), it looks for the exact method signature
  • but method public void foo( String a) is not available in class Alpha
  • so at compile time, the method in class Alpha is chosen
  • but as the program runs, due to polymorphism, the overriding method in class Beta is chosen
  • and hence we get the output subclass and not 5
  • Remember that method polymorphism is only for overrding methods and overrding methods have exactly same signature



  • hope this helps
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic