static void tune(int x ) { System.out.println("called tune from Winda with no arg...: "+x ); }
public static void main(String[] args) {
WindA w1 = new WindA(); Instrument i1 = new Instrument(), i2 = new WindA();
w1.tune(1); i1.tune(2);
i1=w1; i1.tune(3);
}
} ///:~
Output:- ========= D:\siva\reading\java>java WindA Constructor Instrument... Constructor Winda... Constructor Instrument... Constructor Instrument... Constructor Winda... called tune from Winda with no arg...: 1 ...called tune from Instrument with no arg - 2,100 ...called tune from Instrument with no arg - 3,100
void tune(int x ) { System.out.println("called tune from Winda with no arg...: "+x ); }
public static void main(String[] args) {
WindB w1 = new WindB(); Instrument i1 = new Instrument(), i2 = new WindB();
w1.tune(1); i1.tune(2);
i1=w1; i1.tune(3);
}
} ///:~
Output:- ==========
D:\siva\reading\java>java WindB Constructor Instrument... Constructor Winda... Constructor Instrument... Constructor Instrument... Constructor Winda... called tune from Winda with no arg...: 1 ...called tune from Instrument with no arg - 2,100 called tune from Winda with no arg...: 3
When you declare a method as static all references to it will be resolved at compile time rather than at runtime so when the compiler encounters the statemet
i1=w1; it will look for i1 as i1 is the reference of Instrument class the base class method is executing because i1 is actually the reference of Instrument class and late binding is applicable only to non static methods.