• 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

Dynamic Binding????????

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all, Please format your sample code by using < pre > code sample < /pre > . While typing pre tags don't include the space in bet < and > . Thanks for your coperation.

<pre>
class Shape {
static int x = 7, y = 7;
int a_big_no;
int Sizeof;
int getY() {return y;};
}
class SubShape extends Shape {
int x =5, y =5;
int getY() {return y;}
}
class upcast extends Object {
public static void main(String args[]) {
Shape a = new Shape();//creates instance of shape
Shape b = new SubShape();//Creates instance of subshape
System.out.println("a.y = " + a.y + " b.y = "+ b.y);//prints 7 and 7
System.out.println("a.getY() = " + a.getY() +
" b.getY() = " + b.getY());//prints 7 and 5
}
}

</pre>
Why Such behavior ??? why cannot there be dynamic binding for variables???
Why only for methods???
Thanks............

[This message has been edited by maha anna (edited April 19, 2000).]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In my openion, since the above variables are static
their values are known at compile time itself.
Whereas, the exact method which gets invoked is not
known till runtime. Hence you see the difference.
I hope others can explain in more detail....till
then a search could reveal previous discussions
on similar topics which could help you.
Regds.
- satya
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even if they weren't static, it would have behaved
the same way.
Variables are always bound at compile time, unlike
method invocation which is deferred to runtime
resulting in Polymorphism.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic