Lab-4

Lab Description:

This is lab to create a hierarchy, the super class is MobileDevice, under MobileDevice is Smartphone, then under Smartphone is Android, Windowsphone and iPhone. First, I implemented my MobileDevice code, i used setter and getter method. My Smartphone shares the same method from super class(MobileDevice) by using key word extends. Then I override the Smartphone getter method with new code. I did the same for Android,iPhone and Windowsphone, but the super class for these three phones is Smartphone.

Code:

package lab4;

public class MobileDevice {

	/**
	 * @param args
	 */
	private String deviceType;

	public MobileDevice() {
		deviceType = "Mobile Device";
	}

	public void setDeviceType() {

	}

	public String getDeviceType() {
		return deviceType;
	}
}
_____________________________________________________________________
package lab4;

public class SmartPhone extends MobileDevice {

	private String deviceType;

	public SmartPhone() {

		deviceType = "Smart Phone";
	}

	@Override
	public String getDeviceType()

	{
		super.getDeviceType();
		deviceType = super.getDeviceType() + " -> " + deviceType;
		return deviceType;
	}

}
_____________________________________________________________________
package lab4;

public class Android extends SmartPhone {

	private String deviceType;

	public Android() {
		deviceType = "Android";
	}

	@Override
	public String getDeviceType() {
		deviceType = super.getDeviceType() + " -> " + deviceType;
		return deviceType;
	}
}

_____________________________________________________________________
package lab4;

public class iPhone extends SmartPhone {

	private String deviceType;

	public iPhone() {
		deviceType = "iPhone";
	}

	@Override
	public String getDeviceType() {
		deviceType = super.getDeviceType() + " -> " + deviceType;
		return deviceType;
	}
}
_____________________________________________________________________
package lab4;

public class WindowsPhone extends SmartPhone {
	private String deviceType;

	public WindowsPhone() {
		deviceType = "WindowsPhone";
	}

	@Override
	public String getDeviceType() {
		deviceType = super.getDeviceType() + " -> " + deviceType;
		return deviceType;
	}
}
_____________________________________________________________________
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();
		WindowsPhone myWindowsPhone = new WindowsPhone();
		System.out.println(myMobileDevice.getDeviceType());
		System.out.println(mySmartPhone.getDeviceType());
		System.out.println(myiPhone.getDeviceType());
		System.out.println(myAndroid.getDeviceType());
		System.out.println(myWindowsPhone.getDeviceType());
	}
}

Screenshots: