+ Наследование и создание экземпляров
П.С. Подписаться на подкаст тут, скачать подкаст тут.
public class Money {
protected int count;
public Money(int count) {
System.out.println("In the Money constructor, count = " + count);
this.count = count;
}
public int getCount() {
System.out.println("In the Money getCount");
return count;
}
public void setCount(int count) {
this.count = count;
}
}
public class Rub extends Money {
public Rub(int count) {
super(count);
System.out.println("In the Rub constructor, count = " + count);
}
public int getCount() {
System.out.println("In the Rub getCount");
return count;
}
}
public class MoneyCreator {
public static void main(String[] args) {
Money m = new Money(15);
Rub r = new Rub(20);
m.getCount();
r.getCount();
Money mm = new Rub(30);
mm.getCount();
}
}
0 коммент.:
Отправить комментарий