大家帮我看看,这个内部类程序,到底哪里有错误,谢谢!JAVA
classCubic{doublegetCubic(intn){return0;}}abstractclassSqrt{publicabstractdoublegetSq...
class Cubic
{double getCubic(int n)
{return 0;
}
}
abstract class Sqrt
{public abstract double getSqrt(int x);
}
class A
{void f(Cubic cubic)
{double result=cubic.getCubic(3);
System.out.println(result);
}
}
public class Example4_31
{public static void main (String args[])
{A a=new A();
a.f(new Cubic()
{double getCubic(int n)
{return n*n*n;
}
}
};
Sqrt ss=new Sqrt()
{public double getSqrt(int x)
{return Math.sqrt(x);
}
};
double m=ss.getSqrt(5);
System.out.println(m);
}
} 展开
{double getCubic(int n)
{return 0;
}
}
abstract class Sqrt
{public abstract double getSqrt(int x);
}
class A
{void f(Cubic cubic)
{double result=cubic.getCubic(3);
System.out.println(result);
}
}
public class Example4_31
{public static void main (String args[])
{A a=new A();
a.f(new Cubic()
{double getCubic(int n)
{return n*n*n;
}
}
};
Sqrt ss=new Sqrt()
{public double getSqrt(int x)
{return Math.sqrt(x);
}
};
double m=ss.getSqrt(5);
System.out.println(m);
}
} 展开
1个回答
展开全部
class Cubic {
double getCubic(int n){
return 0;
}
}
abstract class Sqrt {
public abstract double getSqrt(int x);
}
class A {
void f(Cubic cubic) {
double result=cubic.getCubic(3);
System.out.println(result);
}
}
public class Example4_31 {
public static void main (String args[]) {
A a=new A();
a.f(new Cubic(){
double getCubic(int n) {
return n*n*n;
}
} ); //加右括号
Sqrt ss=new Sqrt() {
public double getSqrt(int x)
{return Math.sqrt(x); } };
double m=ss.getSqrt(5);
System.out.println(m);
}
}
double getCubic(int n){
return 0;
}
}
abstract class Sqrt {
public abstract double getSqrt(int x);
}
class A {
void f(Cubic cubic) {
double result=cubic.getCubic(3);
System.out.println(result);
}
}
public class Example4_31 {
public static void main (String args[]) {
A a=new A();
a.f(new Cubic(){
double getCubic(int n) {
return n*n*n;
}
} ); //加右括号
Sqrt ss=new Sqrt() {
public double getSqrt(int x)
{return Math.sqrt(x); } };
double m=ss.getSqrt(5);
System.out.println(m);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询