/* CET 3640 Lab 3 - Inheritance Eric Tung 10/7/2013 */ import java.lang.String; public class Lab_3 { public static void main(String args[]) { MobileDevice mobile = new MobileDevice(); SmartPhone smart = new SmartPhone(); Android paranoid = new Android(); iPhone ios = new iPhone(); WindowsPhone window = new WindowsPhone(); System.out.println(mobile.getDeviceType()); System.out.println(smart.getDeviceType()); System.out.println(paranoid.getDeviceType()); System.out.println(ios.getDeviceType()); System.out.println(window.getDeviceType()); } }
import java.lang.String; public class MobileDevice { private String deviceType = new String(); public MobileDevice() { setDeviceType("Mobile Device"); } public String getDeviceType() { return deviceType; } public void setDeviceType(String str) { deviceType = str; } }
public class SmartPhone extends MobileDevice { private String deviceType = new String(); public SmartPhone() { deviceType = "Smart Phone"; } public String getDeviceType() { deviceType = super.getDeviceType() +" -> "+ deviceType; return deviceType; } }
public class Android extends SmartPhone { private String deviceType = new String(); public Android() { deviceType = "Android"; } public String getDeviceType() { deviceType = super.getDeviceType() +" -> "+ deviceType; return deviceType; } }
public class iPhone extends SmartPhone { private String deviceType = new String(); public iPhone() { deviceType = "iPhone"; } public String getDeviceType() { deviceType = super.getDeviceType() +" -> "+ deviceType; return deviceType; } }
public class WindowsPhone extends SmartPhone { private String deviceType = new String(); public WindowsPhone() { deviceType = "Windows Phone"; } public String getDeviceType() { deviceType = super.getDeviceType() +" -> "+ deviceType; return deviceType; } }