이 프로그램을 실행하려면 "derp"메서드를 Shape 클래스에서 직사각형 클래스로 가져와야합니다. 그러나 나 자신이나 교사가 무엇을 시도하든, 우리는 그것을 작동하게 만들 수 없습니다. 내가 실제로 성취해야 할 것은 Shape의 "derp"메소드가 Rectangle에서 작동 할 수 있어야한다는 것입니다. 그러나이 메서드를 가져 오는 작업으로 인해 우리는 어려움을 겪었습니다.Java에서 클래스 가져 오기?
public abstract class shape{
shape(){
}
shape(int length, int width, int thing){
length = 0;
width = 0;
}
public int derp(int thing, int length) {
thing = (int) Math.random() * 9 ;
length = thing;
return length;
}
}
public class Rectangle extends shape {
public static void main(String args[])
{
shape.getLength(Length, Width);
//r1 will take all default value
Rectangle r1 = Rectangle();
//r2 will take all supplied value
Rectangle r2 = Rectangle(4, 5);
//r3 will take supplied length. width will take default value
Rectangle r3 = Rectangle(10);
//r4 will take the same value of r2
Rectangle r4= r2;
//the rest of the code
}
private static void Rectangle(int width2, int length2) {
// TODO Auto-generated method stub
}
}
왜 모양이 사각형을 연장 하는가? 거꾸로 보입니다. 얼핏보기에 – FatalError
은 직사각형처럼 보입니다. 다른 모양이 아닌 모양을 확장해야합니다. – markg
그 점을 지적 해 주셔서 감사합니다. 이제는 Rectangle 메서드 내에서 Shape에서 "Derp"메서드를 사용해야합니다. 그게 가능하니? – user3348422