Revised_Lab_3

Lab Description:
In this lab we are learning how inheritance work, so in the we are creating many classes where the second class will inherit the first class and the third
class will inherit the first and second class and so on.
……………………………………………………………………………………………………….
Lab3.java:

package Lab3;
import java.lang.String;

public class Lab3
{
	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());
	}
}

…………………………………………………………………………………………………….
MobileDevice.java:

package Lab3;
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;
	}
}

………………………………………………………………………………………………………
SmartPhone.java:

package Lab3;

public class SmartPhone extends MobileDevice
{
	private String deviceType = new String();

	public SmartPhone()
	{
		deviceType = "Smart Phone";
	}

	public String getDeviceType()
	{
		deviceType = super.getDeviceType() +" -> "+ deviceType;
		return deviceType;
	}
}

……………………………………………………………………………………………………….
Android.java :

package Lab3;

public class Android extends SmartPhone
{
	private String deviceType = new String();

	public Android()
	{
		deviceType = "Android";
	}

	public String getDeviceType()
	{
		deviceType = super.getDeviceType() +" -> "+ deviceType;
		return deviceType;
	}
}

……………………………………………………………………………………………………….
iPhone.java :

package Lab3;

public class iPhone extends SmartPhone
{
	private String deviceType = new String();

	public iPhone()
	{
		deviceType = "iPhone";
	}

	public String getDeviceType()
	{
		deviceType = super.getDeviceType() +" -> "+ deviceType;
		return deviceType;
	}
}

……………………………………………………………………………………………………….
WindowsPhone.java :

package Lab3;

public class WindowsPhone extends SmartPhone
{
	private String deviceType = new String();

	public WindowsPhone()
	{
		deviceType = "Windows Phone";
	}

	public String getDeviceType()
	{
		deviceType = super.getDeviceType() +" -> "+ deviceType;
		return deviceType;
	}
}

……………………………………………………………………………………………………….
OUTPUT :

Lab3_1

Leave a Reply

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