aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dynamic Binding???????? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Dynamic Binding????????" Watch "Dynamic Binding????????" New topic
Author

Dynamic Binding????????

satish
Greenhorn

Joined: Apr 17, 2000
Posts: 5
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).]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

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
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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.


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Dynamic Binding????????
 
Similar Threads
Object behavior when reassign !
Overridding
Sub classes And casting
recursion - sierpinskys triangle - HELP!!
Overidden variables