Lab Description:
For this lab, I had to use Eclipse to create a script where classes will inherit other classes. This lab was similar to lab 4, but the superclass was an abstract class. For my inheritance tree, I started with the Superclass MobileDevice and another two Superclasses SmartPhone and Tablet under MobileDevice. Then I added one subclass to each of the two Superclasses to finish my hierarchy tree.
Code:
package lab5; abstract class MobileDevice { private String deviceType = "Mobile Device"; public String getDeviceType() { return deviceType; } abstract void setDeviceType(String MobileDevice); } class Tablet extends MobileDevice { private String deviceType = "This device is: Tablet"; public String getDeviceType() { return deviceType; } public void setDeviceType(String deviceType) { this.deviceType = deviceType; } } class iPad extends Tablet { private String deviceType = "This device is: iPad 3"; public String getDeviceType() { return deviceType; } public void setDeviceType(String deviceType) { this.deviceType = deviceType; } } class SmartPhone extends MobileDevice { private String deviceType = "This device is: SmartPhone"; public String getDeviceType() { return deviceType; } public void setDeviceType(String deviceType) { this.deviceType = deviceType; } } class Android extends SmartPhone { private String deviceType = "This device is: Samsung Galaxy 3"; public String getDeviceType() { return deviceType; } public void setDeviceType(String deviceType) { this.deviceType = deviceType; } } public class Lab5 { public static void main (String[] args) { Tablet myTablet = new Tablet(); iPad myiPad = new iPad(); SmartPhone mySmartPhone = new SmartPhone(); Android myAndroid = new Android(); System.out.println(myTablet.getDeviceType()); System.out.println(mySmartPhone.getDeviceType()); System.out.println(myiPad.getDeviceType()); System.out.println(myAndroid.getDeviceType()); } }
Screenshots: