Lab 4

The objective of this lab is to write a Java program that use inheritance. Inheritance is when a subclass is derived from a superclass. it is the same as the concept of inheritance from one family member to another.

Code:

Lab4;

public class MobileDevice {
	private String deviceType;

	public MobileDevice() {

		deviceType = "Mobile Device";
		// TODO Auto-generated constructor stub
	}

	public String getDeviceType() {
		return deviceType;
	}

	public void setDeviceType(String deviceType) {
		this.deviceType = deviceType;
	}

}
Lab4;

public class SmartPhone extends MobileDevice {

	private String deviceType;
	public SmartPhone() {
		deviceType = "SmartPhone";
		// TODO Auto-generated constructor stub
	}
	public String getDeviceType() {
		return deviceType;
	}
	public void setDeviceType(String deviceType) {
		this.deviceType = deviceType;
	}

}
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());
	}
}
Lab4;

public class iPhone extends SmartPhone{

	public iPhone () {
	}

	@Override

	public String getDeviceType() {
		return deviceType = "Mobile Device -> Smart Phone -> IPhone";
	}

}
Lab4;

public class Android extends SmartPhone {

	public Android() {

	}
	@Override

	public String getDeviceType () {
		return deviceType = "Mobile Device -> Smart Phone -> Android";
	}

}
Lab4;

public class WindowsPhone extends SmartPhone {

	public WindowsPhone() {

	}

	@Override
	public String getDeviceType() {
		return deviceType = "Mobile Device -> Smart Phone -> Windows Phone";
	}

}

Screenshots:

Hello world!

This is the first post on your Learning Blog. Edit or delete it, then start blogging!

NOTE: Remember to add appropriate Category and Tags to your posts. This will help your professors and other visitors find the content they are looking for. The Category “Coursework” and the Tags “OpenLab” and “City Tech” have already been applied to this post. Feel free to make changes!