Ch3 "Objects-Classes" getX() should return 3, not 21 #1857
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please type "I already searched for this issue":
I already searched for this issue
Edition: (pull requests not accepted for previous editions)
2nd
Book Title:
objects-classes
Chapter:
3
Section Title:
Overiding methods
Topic:
For the code example (below), shouldn't the result of point.printX(); be x: 3 instead? Given that Point3d is a subclass of Point2d, when Point3d is instantiated as point using the super keyword, it inherits the properties of Point2d:
a. super.getX() refers to the getX() method in Point2d.
b. The getX() method in Point2d returns the x property of Point2d, which is 3.
c. Hence, printX() outputs x: 3.
The code example from the chapter:
class Point2d {
x = 3
y = 4
}
class Point3d extends Point2d {
x = 21
y = 10
z = 5
}
var point = new Point3d();
point.printX(); // x: 21