Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

strange behavior of overridden call

 
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers ,



The output is :
sub1, 2

In line 14 i is printed and then getI() is called. and expected output is : 1, Sub2

But when i execute the code getI() is called and then i is printed and output is (Unexpected) : Sub1, 2

Why call is made before i is printed ??



 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Naveen Yadav,



In Above Code, First Precedence goes to the "ga.getI()" as () operator has higher precedence, so it will call the getI() method of Arabik before printing anything,
1) we have in getI() method of Arabik which will print "Sub" First
2) later above code i.e., line 1 starts print the content from left to right as + operator has left to right associativity, so ga.i will print the value of "1" , because you can't override the instance variable in inheritance.
3) Then It prints ","
4) Then returned value of ga.getI() method of Arabik, which is "2"


so you are getting Sub1 , 2

Please correct me if i am wrong anywhere and i am much interested to see how other people are thinking and describing the answer, which will help us to understand more about the topic

Thanks & Regards
S.Sathiya
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
quite right,
we can say instance variables of the super class get hidden in the subclass. we can access them through the super class which is happing in the above code and also your precedence explanation is right i believe.
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic