public class Test { |
public void test1(A a){ |
a.doSth(); |
} |
public static void main(String[] args) { |
Test t = new Test(); |
A a = new B(); |
t.test1(a); |
} |
} |
interface A{ |
public int doSth(); |
} |
class B implements A{ |
@Override |
|
|
public int doSth() { |
System.out.println( "now in B" ); |
return 123 ; |
} |
} //源代码片段来自云代码http://yuncode.net |
|
public class Test { |
public void test1(A a){ |
a.doSth(); |
} |
public static void main(String[] args) { |
Test t = new Test(); |
A a = new B(); |
t.test1(a); |
} |
} |
interface A{ |
public int doSth(); |
} |
class B implements A{ |
@Override |
|
|
public int doSth() { |
System.out.println( "now in B" ); |
return 123 ; |
} |
} //源代码片段来自云代码http://yuncode.net |
|