-
단일상속 extends Object & 접근지정자 protected & super,this개발노하우/Java 2007. 5. 7. 11:52
import java.lang.*; // 생략된 형태
class AA extends Object{
int x = 100;
}class BB extends AA{
int y = 200;
}class CC extends BB{
int z = 300;
}public class object extends Object{
public static void main(String arg[]){
CC cp = new CC();
System.out.println("z ="+cp.z);
System.out.println("y ="+cp.y);
System.out.println("x ="+cp.x);
}
}
=================================================================================
//접근 지정자 protected
class AA{
protected int x = 100;
protected int y = 200;
public void disp(){
System.out.println("x= "+x);
System.out.println("y= "+y);
}
}class BB extends AA{
private int z = 300;
public void disp_BB(){
System.out.println("x= "+x);
System.out.println("y= "+y);
System.out.println("z= "+z);
}
}public class object extends Object{
public static void main(String arg[]){
BB bp = new BB();
bp.disp_BB();
}
}
=================================================================================
// 상속 super, this
class AA{
protected int x = 100;
protected int y = 200;
}class BB extends AA{
private int x = 300;
private int y = 400;
public void disp_BB(){
System.out.println("x= "+this.x);
System.out.println("y= "+super.y);
}
}public class object extends Object{
public static void main(String arg[]){
BB bp = new BB();
bp.disp_BB();
}
}
//다중상속
http://kin.naver.com/db/detail.php?d1id=1&dir_id=10106&eid=6OlzAj11jEBC69nMnZgli5VhEzzUi25A&qb=tNzAz7vzvNM=