4.1 Give an example of polymorphism and what will be inherited between classes.
Let's say you have an Animal class that you created. Within this animal class, you have a method called move because animals move. From this animal class, let's say you create more classes that extends animal. Let's call them Dog and Cat. These classes will also inherit the move method but you can define them differently for each class. Java will have the ability to know which object the method is being called from and use that interpretation of the move method.
4.2 After the learning this week, can you identify the difference between Abstract classes and Interfaces? Be specific.
Interface: An interface is a blueprint that can be used for class implementation (not considered a class). Within the body of this class, it does not have any concrete methods thus all methods are considered abstract methods. An interface cannot be instantiated but classes that IMPLEMENT interfaces can be.
Abstract class: Abstract classes are classes that can be used as a blueprint to create concrete classes. This class has at least one abstract methods (without a body) and multiple concrete methods. This type of class cannot be instantiated.
Specific differences:
1. Methods: interface has abstract methods while abstract class can have both abstract and concrete methods.
2. Variables: Interface variables can only be static and final while abstract classes can contain non-final and non-static variables.
3. Implementation: Abstract class can provide implementation of interface but vice versa is not allowed.
4. Inheritance vs. abstraction: Abstract class uses "extends" to be extended while interface uses "implements" in order to be implemented.
5. Data members: Interface has public data by default while abstract class members can have private, protected, and etc.
4.3 Assignment
The assignment for this week is quite challenging. I did not have the proper time that I want to work on it on my own due to health emergency but I did the best I can. I hope to refocus for this upcoming week so that I can get good headway of the assignment and be more settled before the weekend. Overall, everyone did the parts they were assigned and helped one another on parts they didn't understand. Great project overall.
No comments:
Post a Comment