Question: Inheritance and Super Practice This section will briefly cover the super keyword and how it works with inheritance. Person Create a class in the com.day3.practicel

 Inheritance and Super Practice This section will briefly cover the superkeyword and how it works with inheritance. Person Create a class in

Inheritance and Super Practice This section will briefly cover the super keyword and how it works with inheritance. Person Create a class in the com.day3.practicel package called Person. Create the constructor, getters, and setters as follows: Person firstName : String .lastName : String Person getFirstName(): String setFirstName(String): void getLastName(): String setLastName(String):void Rebel Create a class in the com.day3.practice1 package called Rebel that extends Person. Add a new variable with a setter and a getter. Rebel rebelld: String Rebel(String) getRebelld(): String setRebelld (String): void PersonDemo Create a PersonDemo class with a main method. Inside the main, create a Rebel, passing in the string "R231" for the rebel ID. Then fetch the rebells from the rebel object and display it to the console. Rebel rebel = new Rebel("R231"); Changing the Super Class Change the Person class constructor as follows: public Person (String firstName, String lastName) { super(); this.firstName firstName; this.lastName lastName; } = Note that there is an error for the rebel constructor. The error is the line that says super(); It is erroring out because now the Person constructor requires a first name and a last name to be passed in. Changing the subclass Update the Rebel constructor as follows: public Rebel (String firstName, String lastName, String rebelId) { super(firstName, lastName); this.rebelId - rebelId; } Changing the Person Demo Now, we have to update PersonDemo to pass in the first name and last name as well as the rebel ID. Rebel rebel = new Rebel("Lucas", "Groundrunner", "R231"); Now display the person's first and last name by using the getters. Note that the getFirstName and getLastName methods are in the parent class (Person) and not in the child class (Rebel). The Rebel class inherits all of the class variables and methods found in the Person class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!