-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d0467d
commit 93dd9df
Showing
14 changed files
with
147 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package samples.inheritance.instancefield; | ||
|
||
public class InheritanceInstanceField { | ||
public static void main(String[] args) { | ||
Child child = new Child(); | ||
int sum1 = // sum must be 14 | ||
child.getChildOnlyField() // 5 from Child | ||
+ child.getParentField() // 3 from Parent (absent in Child, is taken from Parent) | ||
+ child.getGrandParentField() // 4 from Parent (Parent shadows GrandParent) | ||
+ child.getGrandParentOnlyField(); // 2 from GrandParent (nor Child neither Parent have it) | ||
|
||
child.setGrandParentOnlyField(102); | ||
|
||
int sum2 = // sum must be 114 | ||
child.getChildOnlyField() // 5 from Child | ||
+ child.getParentField() // 3 from Parent (absent in Child, is taken from Parent) | ||
+ child.getGrandParentField() // 4 from Parent (Parent shadows GrandParent) | ||
+ child.getGrandParentOnlyField(); // 102 from modified GrandParent (nor Child neither Parent have it) | ||
|
||
int result = sum1 + sum2; // sum must be 128 | ||
} | ||
} | ||
|
||
class GrandParent { | ||
protected int grandParentField = 1; | ||
protected int grandParentOnlyField = 2; | ||
} | ||
|
||
class Parent extends GrandParent { | ||
protected int parentField = 3; | ||
protected int grandParentField = 4; | ||
} | ||
|
||
class Child extends Parent { | ||
private int childOnlyField = 5; | ||
|
||
public int getChildOnlyField() { | ||
return childOnlyField; | ||
} | ||
|
||
public int getParentField() { | ||
return parentField; | ||
} | ||
|
||
public int getGrandParentField() { | ||
return grandParentField; | ||
} | ||
|
||
public int getGrandParentOnlyField() { | ||
return grandParentOnlyField; | ||
} | ||
|
||
public void setGrandParentOnlyField(int grandParentOnlyField) { | ||
this.grandParentOnlyField = grandParentOnlyField; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+28 Bytes
(100%)
tests/test_data/samples/arithmetics/extremestack/ints/ExtremeStackInt.class
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
tests/test_data/samples/fields/instance/ints/InstanceFields.class
Binary file not shown.
Binary file modified
BIN
+152 Bytes
(120%)
tests/test_data/samples/fields/instance/ints/InstanceFieldsUserInts.class
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+343 Bytes
tests/test_data/samples/inheritance/instancefield/GrandParent.class
Binary file not shown.
Binary file added
BIN
+662 Bytes
tests/test_data/samples/inheritance/instancefield/InheritanceInstanceField.class
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters