"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Originally posted by lu v thuan:
Hi ravish and FEI Ng:
If no dynamic binding why this code give compile time error
<pre>
class Parent{
/*public void method1()
{
System.out.println("Parent's method1()");
}*/
public void method2() {
System.out.println("Parent's method2()");
method1(); // U remove(comment) this line u won't get compile time error
}
}
class Child extends Parent{
public void method1(){
System.out.println("Child's method1()");
}
public static void main(String args[]){
Parent p = new Child();
p.method2();
}
}
</pre>
Note : This proves that when compling Java compiler checks the existence of method1() in Parent class
But if you remove Parent's method1() comment. It compliles sucessfully and when running method1 in Child is called even though in compile time the compiler checked if thod1 in class Parent
------->Dynamic Binding Exists
Could you please explane why method1 in class Child not in class Parent is called ?
[This message has been edited by lu v thuan (edited November 07, 2001).]
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
A feeble attempt to tell you about our stuff that makes us money
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|