= abstract를 이용하여 score를 작성할 수 있다 (O)
1. 현상
main() 메소드에 입력한 데이터 값이 계산 메소드로 전달되지 못함.
2. 원인
public Circle_ex(double r) { super(new Point(r,r)); }
3. 해결
double r 파라미터 경우의 메서드 작성할 때, 부모클래스에서 상속받은 Point클래스를 새로 생성했음 => 새로 입력한 데이터값이 정상적으로 반영됨.
오류 발생한 부분의 전체 소스코드
class Point{ //필드 double x,y; //기본생성자 public Point() { super(); } //파라미터생성자 public Point(double x, double y) { super(); this.x = x; this.y = y; } public Point(Point p) { } } abstract class Shape_ex{ private Point p; // x,y public Shape_ex() {this(new Point(0,0));} //좌표 0,0으로 초기화 public Shape_ex(Point p) { super(); this.p=p; } public Point getP() {return p;} public void setP(Point p) { this.p = p; } abstract double calcArea(); //넓이 구하는 추상메소드 } class Circle_ex extends Shape_ex{ //필드 double r; //기본생성자 public Circle_ex() { super(); } //파라미터 생성자 public Circle_ex(double r) { super(new Point(r,r)); } //오버라이즈 넓이계산 @Override double calcArea() { return getP().x*getP().x*Math.PI; } }
팀프로젝트 주제를 '직방'으로 정했다.
생각보다 더 많은 시간이 소요될 것 같다는 직감이 들었다.
깃허브로 블로그를 작성하고 싶어서 이번주에 계속 시도하고 있는데 너무 어렵다!!!!!!
벨로그에 계속 작성해야 할 것 같다😥