Lab Description:
For this lab, I had to use Eclipse to create a script where classes will inherit other classes. For my inheritance tree, I started with the Superclass MobileDevice and another Superclass SmartPhone under MobileDevice. then I added three Subclasses to the Superclass SmartPhone to finish my hierarchy tree.
Code:
class MobileDevice { private String deviceType = "Mobile Device"; public String getDeviceType() { return deviceType; } public void setDeviceType(String MobileDevice) { this.deviceType = MobileDevice; } } class SmartPhone extends MobileDevice { private String deviceType = "Mobile Device -> Smart Phone"; public String getDeviceType() { return deviceType; } public void setDeviceType(String deviceType) { this.deviceType = deviceType; } } class Android extends SmartPhone{ private String deviceType = "Mobile Device -> Smart Phone -> Android"; public String getDeviceType() { return deviceType; } public void setDeviceType(String deviceType) { this.deviceType = deviceType; } } class iPhone extends SmartPhone{ private String deviceType = "Mobile Device -> Smart Phone -> iPhone"; public String getDeviceType() { return deviceType; } public void setDeviceType(String deviceType) { this.deviceType = deviceType; } } class WindowsPhone extends SmartPhone{ private String deviceType = "Mobile Device -> Smart Phone -> WindowsPhone"; public String getDeviceType() { return deviceType; } public void setDeviceType(String deviceType) { this.deviceType = deviceType; } } public class MobileDeviceClient { public static void main(String[] args) { 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: