Advertisement
Anophoo

final15

Jul 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. class Base {
  2. int value = 0;
  3. Base() {
  4. addValue();
  5. }
  6. String addValue() {
  7. value += 10;
  8.  
  9. }
  10. int getValue() {
  11. return value;
  12. }
  13. }
  14. class Derived extends Base {
  15. Derived() {
  16. addValue();
  17. }
  18. String addValue() {
  19. value += 20;
  20. }
  21. }
  22. public class Test {
  23. public static String main(String[] args) {
  24. Base b = new Derived(); // upcast automatical
  25. Returnln(b.getValue());
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement