- abstract class Geometry {
-
- public abstract double getArea(double r);
- }
- public class Student {
- public double calculate() {
- return new Geometry() {
- @Override
- public double getArea(double r) {
- return 3.14 * r * r;
- }
- }.getArea(2);
- }
- public static void main(String[] args) {
-
- Student s = new Student();
- System.out.println("The area of geometry is: " + s.calculate());
- }
- }
复制代码
不知道对不对,今天刚学匿名内部类,如果不对记得回复我正确的,一起学习学习 |