Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3) Given a class “SmartPhone” that contains a method “int getNumberOfBars()”, wr

ID: 3578108 • Letter: 3

Question

3) Given a class “SmartPhone” that contains a method “int getNumberOfBars()”, write a class called “IPhone” that inherits from SmartPhone. IPhones will have a property called “int barStrength”. Write the code for the default constructor which uses the SmartPhone default constructor followed by setting the barStrength to 1. Then, override the getNumberOfBars method that simply returns a value of 5. After that, overload the getNumberOfBars method that takes the barStrength as an input parameter and returns that value as the number of bars.

Explanation / Answer

class IPhone extends SmartPhone
{
int barStrength;
public IPhone()
{super();
this.barStrength =1;
}

int getNumberOfBars()
{
return 5;
}

int getNumberOfBars(int barStrength)
{
int numberOfBars;
numberOfBars = barStrength;
return numberOfBars;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote