자바공부하기 57

접근제어

 

 

Class Father {

public int age;

public long height;

private float weight;

}

 

class Son extends Father {

float getWeight() {

return weight;

}

}

 

public class AccessControlMain {

public static void main(String[] args) {

Son son = new Son();

// Upcasting

Father son1 = son;

son1.age= 100;

son1.height = 170L;

son1.weight = 49.0F;

System.out.println("age". + son1.age);

System.out.println("height" + son1. height);

System.out.println("weight" + son1.weight);

System.out.println("weight:" + son.getWeight());

}

}

 

+ Recent posts