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;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.