1-2 Lab5
Understanding inheritance and subclass
Lab5's main goal is understanding and getting used to inheritance and subclass. Therefore I have to be able to demonstrate how they work and connect each parts after this lab5.
These are example of questions.
1. Can you instantiate the BasicShape class into an object?
My answer for this is yes. I could instantiate the BasicShape class into an object with extends.
2. How does an abstract method like getArea() differ from an abstract class, like BasicShape?
I actually want to give more specific details for this questions but so far, my understanding is that an abstract class is a template itself. It can't be instantiated but, by using abstract method, I could use it as a method.
3. Does equals() do the same thing as ‘==’ when comparing two objects? Why?
Yes, because, it's equals() method is following below.
Indicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation on non-null object references:
•It is reflexive: for any non-null reference value x, x.equals(x) should return true.
•It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
•It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
•It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
•For any non-null reference value x, x.equals(null) should return false.
The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).
4. When comparing objects using your overriden equals() method, does it matter whether you use A.equals(B), or B.equals(A)? (Are you sure?)
---
5. What will be the result if you remove the word super from super.equals()?
Super is used the equal method in super class, parent class or base class.
It won't be executed equals() in super class without super.
Comments
Post a Comment