Lab #4

The objective of this lab is to write a Java program that utilizes the inheritance functions. Inheritance is when a subclass gains the rights straight from the superclass. It is the same as the concept of inheritance from one family member to another in terms of genetics.

Code:

Lab4;

public class MobileDevice {
private String deviceType;

public MobileDevice() {

deviceType = “Mobile Device”;
}

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”;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}

}

Lab4;

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

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:
Screenshot

Leave a Reply

Your email address will not be published. Required fields are marked *