Question: CSCI 282 Lab 90 Purpose: Get more practice with: Interfaces, abstract classes, final methods, final classes Overriding toString0 method, and polymorphism. Directions Use Eclipse in
CSCI 282 Lab 90 Purpose: Get more practice with: Interfaces, abstract classes, final methods, final classes Overriding toString0 method, and polymorphism. Directions Use Eclipse in the comments Download the files and add the code described Notice how the FamilyCar class is NOTfinal o This allows us to make subclasses like FamilyCarslowerModel The SportsCar class IS final and so it prevents us from making subclasses Try to create a new class called el that extends sportscar o Eclipse gives you an error and your program won't compile Also notice that the ha and the stop methods of FamilyCar are both final methods o Try to override these two methods in the class FamilyCarslowerModel o Eclipse gives you an error and your program won't compile because you are trying to override final methods, which isn't allowed When you are overriding the other methods, try to override them both with and without using the 6Poverride annotation o without the eoverride annotation, try to make a mistake such as naming the method wrong and see how there are no errors that come up. The wrong method will be called since you didn't properly override the method but Eclipse will not produce any errors o with the override annotation, try to make a mistake and see how Eclipse won't let you compile the code o Remember that when you override a method, you can either match the visibility of the super class's method or you can make it less restrictive but not more restrictive For example if the super class's method is protected, the overridden method can be either protected or public but NOT private Try this out with the Ooverride annotation and see the error it produces o Also remember that to override a method, the return value, the name and the parameters must match, Again, try to make mistakes with the @override annotation to see how these mistakes are caught and what errors they produce. The Car abstract class actually contains an implementation for the stop method But the Car class doesn't implement the Vehicle interface Since the FamilyCar, SportsCar and Prius classes inherit from the Car class, we can simply call super stop0 to use our super class's stop method to satisfy the Vehicle interface's need for a stop method This allows us to not have to write a different stop method for each subclass since the results are the same for all classes
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
