lab4

Lab Description:

In this lab we are to create a superclass name MobileDevice. Than one subclass SmartPhone by using the keyword extends that inherit the superclass that is MobileDevice. Than three more subclass Android, iPhone and WindowsPhone that inherit from SmartPhone. Using the set and getter methods. Than by using the override keyword i override the MobileDevice getter methods and use the SmartPhone codes. Repeat the override method with the Android, iPhone and WindowsPhone.

CODE

package lab4;

public class MobileDevice {

	private String deviceType = "Mobile Device";

	public void setDeviceType() {
	}

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

}
package lab4;

public class SmartPhone extends MobileDevice {

	private String deviceType ;

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

	@Override
	public String getDeviceType() {
		// TODO Auto-generated method stub
		deviceType = super.getDeviceType() +" -> " + deviceType;
		return deviceType;
	}

}
package lab4;

public class Android extends SmartPhone {

	private String deviceType ;

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

	@Override
	public String getDeviceType() {
		// TODO Auto-generated method stub
		deviceType = super.getDeviceType() +" -> " + deviceType;
		return deviceType;
	}

}
package lab4;

public class iPhone extends SmartPhone {

	private String deviceType ;

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

	@Override
	public String getDeviceType() {
		// TODO Auto-generated method stub
		deviceType = super.getDeviceType() +" -> " + deviceType;
		return deviceType;
	}

}
package lab4;

public class WindowsPhone extends SmartPhone {

	private String deviceType ;

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

	@Override
	public String getDeviceType() {
		// TODO Auto-generated method stub
		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());
	}
}

 

Screen shot: