Objective:
This lab was confusing at first because i did not know we had to create so many classes but once i read the whole lab i had an idea how to begin. So first I created a MobileDevice class which was the header, which was going to content as many subclasses as i wanted to add. In this classes i created five classes which its respective private field.

 

Code:

MobileDevice

package lab4;

public class MobileDeviceClient
{
	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		MobileDevice myMobileDevice = new MobileDevice();
		SmartPhone mySmartPhone = new SmartPhone();
		Iphone myIphone = new Iphone();
		Android myAndroid = new Android();
		WindowPhone myWindowPhone = new WindowPhone();
		System.out.println(myMobileDevice.getDeviceType());
		System.out.println(mySmartPhone.getDeviceType());
		System.out.println(myIphone.getDeviceType());
		System.out.println(myAndroid.getDeviceType());
		System.out.println(myWindowPhone.getDeviceType());
	}
}

Android

package lab4;
public class Android extends SmartPhone 
{
	private String Android = "Mobile Device--> SmartPhone--> Android";

	public void setDeviceType()
	{
		this.Android = "Android";

	}
	public String getDeviceType()
	{
		return this.Android; }
}


WindowsPhone
package lab4;

public class WindowPhone extends SmartPhone
{
	private String WindowPhone="Mobile Device--> SmartPhone--> Windows Phone";
	public void setDeviceType()
	{
		this.WindowPhone = "WindowPhone";
	}
	public String getDeviceType()
	{
		return this.WindowPhone;
	}
}

Iphone
package lab4;

public class Iphone extends SmartPhone
{
	private String Iphone= "Mobile Device--> SmartPhone--> Iphone";
	public void setDeviceType() 
	{
		this.Iphone = "Iphone";

	}
	public String getDeviceType()
	{
		return this.Iphone;
	}
}

SmartPhone
package lab4;

public class SmartPhone extends MobileDevice {

	private String SmartPhone = "Mobile Device--> SmartPhone";

	public void setDeviceType() 
	{
		this.SmartPhone = "SmartPhone";
	}
	public String getDeviceType()
{
	return this.SmartPhone; }
}
MobileDevice
package lab4;

public class MobileDevice {

	private String deviceType = "Mobile Device";

	public void setDeviceType() {

	}
	public String getDeviceType()
	{
		return this.deviceType;
	}
}