class A {
private String name;
protected void set(String nm) {
name = nm;
}
public A(String name) {
this.name = name;
}
public String toString() {
return "I'm " + name;
}
}
class B extends A {
private int i;
public B(String name, int i) {
super(name);
this.i = i;
}
public void change(String name, int i) {
set(name); // Available because it's protected
this.i = i;
}
public String toString() {
return " " + i + ": " + super.toString();
}
}
public class MainClass {
public static void main(String[] args) {
B orc = new B("A", 12);
System.out.println(orc);
orc.change("B", 19);
System.out.println(orc);
}
}
|