객체지향 7가지 소스 or 스코프란?
- 최초 등록일
- 2008.12.09
- 최종 저작일
- 2008.05
- 7페이지/ 한컴오피스
- 가격 1,000원
소개글
객체지향의 7가지 소스와
2가지의 스코프를 정리
목차
없음
본문내용
[추상화]
abstract class Shape {
abstract double area();
abstract double circum();
}
class Rectangle extends Shape {
protected int width; //가로길이 변수입니다
protected int height; //세로길이 변수입니다.
public Rectangle(int x, int y) {
//이렇게 해야 이 constructor가 가로가 x이고 세로가 y라는 것
width = x;
height = y;
}
public double area() {
//여기도 마찬가지로 맨 위에 instance variable을 사용해야 합니다(전역변수)
return width * height;
}
public double circum() {
//여기도 마찬가지
return 2*width + 2*height;
}
}
class Circle extends Shape {
//여기도 전역변수를 먼저 설정해 주셔야 합니다.
//메소드 이외에는 이 전역변수를 활용하셔야 합니다.
protected int radius;
protected double area; //PI는 int가 아니니까 double로
public Circle(int x) {
radius = x;
area = Math.PI * x*x;
}
public double area() {
return area;
}
public double circum() {
return 2*radius * Math.PI ;
}
}
참고 자료
없음