当前位置:课程学习>>第四章 面向对象基础>>学习内容>>知识点七
同学们,请运用你学到的知识,尝试分析下面的案例。
案例:根据所学知识分析下面程序,请说出E类中中【代码1】和【代码2】的输出结果。
interface A{
double f(double x,double y);
}
class B implements A{
public double f(double x,double y){
return x*y;
}
int g(int a,int b){
return a+b;
}
}
public class E{
public static void main(String args[]){
A a=new B();
System.out.println(a.f(3,5)); //【代码1】
B b=(B) a;
System.out.println(b.g(3,5)); //【代码2】
}
}