java java java

 

这个写interface 和 class就能完成。

这个主要用到接口和实现的问题:

 

如有帮助请在我的回答上点个【采纳】

myItfc接口:

package com.test.server;

public interface myItfc {
	public double area(double a);
}

测试类:

package com.test.server;

public class TestInterface implements myItfc {

	@Override
	public double area(double a) {
		// TODO Auto-generated method stub
		return a*a*a;
	}
	
	public static void main(String[] args) {
		TestInterface t = new TestInterface();
		System.out.println(t.area(2)); 
	}

}

 

package T1;

public class Test implements MyItfc {

	@Override
	public double area(double param) {
		// TODO Auto-generated method stub
		return Math.pow(param, 3);
	}

	public static void main(String[] args) {
		Test test = new Test();
		System.out.println(test.area(10));
	}

}

interface MyItfc {

	double area(double param);

}