• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Shallow in static method ?

 
Ricardo Polero
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, folks !
from javacaps
class MyTest {
public void myTest() {
System.out.println("Printing myTest in MyTest class");
}
public static void myStat() {
System.out.println("Printing myStat in MyTest class");
}
}
public class Test extends MyTest {
public void myTest() {
System.out.println("Printing myTest in Test class");
}
public static void myStat() {
System.out.println("Printing myStat in Test class");
}
public static void main ( String args[] ) {
MyTest mt = new Test();
mt.myTest();
mt.myStat();
}
}
C) Printing myTest in MyTest class followed by Printing myStat in MyTest class
I undestand perfect how de runtime choose the method , but I wnat to undestand the process when the method is static.
Why didn't choose the static version in Test if "this " reference is Test ? Why choose from MyTest ?
Thnaks in advance
 
vivek bawge
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static methods never use dynamic binding. They are bound compile time.
 
Ricardo Polero
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
Ricardo
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic