/** CastTest.java */
class A{}
class B extends A
{
public void f()
{
System.out.println("f() in B");
}
}
public class CastTest
{
public static void main(String args[])
{
A a = new B();
((B)a).f();
(B)a.f(); //
error: not a statement
a.f();
/* error: cannot find symbol
a.f(); // error
^
symbol: method f()
location: variable a of type A */
}
}
static method: compile-time binding
instance method: run-time binding
http://www.javaprogrammingforums.com/java-programming-tutorials/3117-static-fields-inheritance.html
http://www.artima.com/forums/flat.jsp?forum=1&thread=3620
待查: static block
static method: compile-time binding
instance method: run-time binding
http://www.javaprogrammingforums.com/java-programming-tutorials/3117-static-fields-inheritance.html
http://www.artima.com/forums/flat.jsp?forum=1&thread=3620
待查: static block
沒有留言:
張貼留言