Father 클래스
public class Father {
private int priVal;
protected int proVal;
public int pubVal;
public void setPri(int x) {
priVal = x;
}
public Father() {
System.out.println("Father constructor call");
}
public Father(int priVal, int proVal, int pubVal) {
System.out.println("arg Father constructor call");
this.priVal = priVal;
this.proVal = proVal;
this.pubVal = pubVal;
}
public void pubFn() {
System.out.println("pubFn");
}
protected void proFn() {
System.out.println("proFn");
}
private void priFn() {
System.out.println("priFn");
}
}
Child 클래스
public class Child extends Father {
public int childVal;
public Child() {
System.out.println("Child constructor call");
}
public Child(int childVal) {
super (30,40,50);
System.out.println("arg Child constructor call");
this.childVal = childVal;
}
public void chFn() {
proVal = 30;
proFn();
}
}
Body 클래스
public class Baby extends Child {
public int babyVal;
public Baby() {
System.out.println("Baby constructor call");
}
public Baby(int babyVal) {
super(20);
System.out.println("arg Baby constructor call");
this.babyVal = babyVal;
}
public void babyFn() {
proVal = 40;
}
public void babyFn1() {
}
}
main 1
public class study40 {
public static void main(String[] args) {
Child child = new Child();
child.childVal = 10;
child.pubVal = 40;
child.pubFn();
}
}
main 2
public class study41 {
public static void main(String[] args) {
Baby baby = new Baby();
baby.babyVal = 10;
baby.childVal = 20;
baby.pubVal = 30;
baby.pubFn();
}
}
main 3
public class study42 {
public static void main(String[] args) {
Baby baby = new Baby();
baby.pubVal = 10;
baby.childVal = 20;
baby.babyVal = 30;
baby.babyFn();
baby.setPri(50);
}
}