Question: Add another constructor to SmartPhone. Make this constructor accept a name, phone, and email. Save name and phone in the superclass and save email in

Add another constructor to SmartPhone. Make this constructor accept a name, phone, and email. Save name and phone in the superclass and save email in SmartPhone (subclass).
Also In SmartPhone, add the method
public String getEmail()
Make this method return the email address that was passed to the constructor.
Test Case 1
Name: Allan Hancock College Phone: 8059226966
Area code: 805
Prefix: 922
Line number: 6966
Email: hello@hancockcollege.edu
---
Name: In-N-Out Burger Phone: 8007861000
Area code: 800
Prefix: 786
Line number: 1000
Email: null
---
Name: Costco Wholesale Phone: 8059288459
Area code: 805
Prefix: 928
Line number: 8459
Email: example@costco.com
---public class Demo5
{
public static void main(String[] args)
{
Phone p1= new SmartPhone("Allan Hancock College", 8059226966L, "hello@hancockcollege.edu");
Phone p2= new SmartPhone("In-N-Out Burger", 8007861000L);
Phone p3= new SmartPhone("Costco Wholesale", 8059288459L, "example@costco.com");
System.out.println(p1);
test(p1);
System.out.println(p2);
test(p2);
System.out.println(p3);
test(p3);
}
public static void test(Phone p){
//this will confirm that SmartPhone is a subclass of phone
SmartPhone sp =(SmartPhone)p;
System.out.println("Area code: "+ sp.getAreaCode());
System.out.println("Prefix: "+ sp.getPrefix());
System.out.println("Line number: "+ sp.getLineNumber());
System.out.println("Email: "+ sp.getEmail());
System.out.println("---");
}
} public class Phone
{
protected String name;
protected long number;
public Phone(String name, long number){
this.name = name;
this.number = number;
}
public String toString(){
return "I am a phone!";
}
}

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 Programming Questions!