我有一个抽象的类叫做动物à在它里面我有一个抽象的方法叫做乘法。如何检查这个方法是抽象的还是不使用JUnit5?
public abstract class Animal {
private final int age;
private final int speed;
public Animal (int age,int speed) {
if(age > 0) {
this.age = age;
}
else {
throw new IllegalArgumentException("Age can't be less than 0");
}
if(speed > 0) {
this.speed = speed;
}
else {
throw new IllegalArgumentException("Speed can't be less than 0");
}
}
public static void main(String[] args) {
}
@Override
public boolean equals(Object anotherObject) {
if (this == anotherObject) {
return true;
}else {
return false;
}
}
public abstract Animal[] multiply(int n);
private boolean isFaster(Animal a) {
if(this.getSpeed() >a.getSpeed()) {
return true;
}else {
return false;
}
}
private boolean isOlder(Animal a) {
if(this.getAge() >a.getAge()) {
return true;
}
return false;
}
@Override
public String toString() {
return this.getClass()+ "is " + this.getAge() + " years old, is " +this.getSpeed() +" units fast.";
}
public final int getAge() {
return age;
}
public final int getSpeed() {
return speed;
}
}
我知道如何通过输入这个
Class<Animal> clazz = Animal.class;
Assertions.assertTrue(Modifier.isAbstract(clazz.getModifiers()));
如何对抽象方法进行等价处理?
暂无答案!
目前还没有任何答案,快来回答吧!