Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 생성자
- Menu
- Android
- 오버로딩
- 메소드
- oracle
- 에러페이지
- Graphic
- layout
- AWT
- 클래스
- 기본
- 안드로이드
- JavaScript
- Spring
- JSP
- mybatis
- OGNL
- 어노테이션
- HTML
- 국제화
- Java
- Eclips
- struts2
- 배열
- 이클립스
- 예외처리
- paint
- 전화걸기
- 메서드
Archives
- Today
- Total
note
super 연습문제 (에러 찾기) 본문
package com.over3;//super에러 해결하기
public class PointTest {
public static void main(String[] args){
Point3D p3 = new Point3D(1,2,3);
System.out.println(p3.getLocation());
}
}
//Point(){}
class Point{
int x;
int y;
String getLocation(){
return "x :"+x+", y :"+y;
}
}
class Point3D extends Point{
int z;
Point3D(int x, int y, int z){
/*2.에러 해결방법
부모 클래스에 default 생성자가 없고
인자를 전달해야 하는 생성자만 있을경우
명시적으로 super(인자)를 이용해서 부모클래스 생성자 호출
super(x,y);*/
this.x = x;
this.y = y;
this.z = z;
}
String getLocation(){//오버라이딩
return "x : " +x+", y :"+y+"m z :" + z;
}
}
x : 1, y :2m z :3
'자바 > 오버라이딩' 카테고리의 다른 글
super로 은닉된 슈퍼클래스의 멤버변수 접근하기 (0) | 2011.12.20 |
---|---|
Super 기본 정수 (0) | 2011.12.20 |
메소드 오버라이딩 super 참조 변수 (0) | 2011.12.20 |
메소드 오버라이딩 (0) | 2011.12.20 |