This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static & early binding

 
Rr Kumaran
Ranch Hand
Posts: 548
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,




In the above code snippet,

1. what is the difference between lines 22 and 23 ?
2. why the statement on line 25 prints class parent's instance variable 'a' instead of class child's instance variable 'a' ?


Thanks & Regars,
Kumar.
 
Junilu Lacar
Bartender
Pie
Posts: 7778
62
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. what is the difference between lines 22 and 23 ?

The cast in line 22 is unnecessary and has no effect on how any of the succeeding statements will be executed.

2. why the statement on line 25 prints class parent's instance variable 'a' instead of class child's instance variable 'a' ?

Because unlike the non-static methods, instance variables do not participate in polymorphism and are resolved at compile time.
[ June 14, 2004: Message edited by: Junilu Lacar ]
 
Rr Kumaran
Ranch Hand
Posts: 548
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lucar.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic