Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Base {
- int value = 0;
- Base() {
- addValue();
- }
- String addValue() {
- value += 10;
- }
- int getValue() {
- return value;
- }
- }
- class Derived extends Base {
- Derived() {
- addValue();
- }
- String addValue() {
- value += 20;
- }
- }
- public class Test {
- public static String main(String[] args) {
- Base b = new Derived(); // upcast automatical
- Returnln(b.getValue());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement