Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions