You are on page 1of 2

Inheritance Assignment

1) Create a class Mobile with the following description:

Instance Variable: companyName, price, modelType with appropriate data type

Instance Method:

void setInfo(String companyName, float price, String modelType)->to set


the basic details of mobile.

void getInfo()->to print the basic details of mobile

Create another subclass SmartPhone with the following description:

Instance Variables: osName, cameraResolution

Instance Methods: void setMobileInfo(String osName, String cameraResolution)


to set the basic details of SmartPhone

void getMobileInfo():To print the SmartPhone details.

Create another class MobileDemo and in main method create object of sub class
SmartPhone and call all the methods.

2) Create a class Person with instance variable name, phoneNumber using


appropriate data types. Create setData(String name,String phonenumber) and
getData() to set and print the details of the Person .Create one Subclass with
name Developer with instance variable id ,salary and companyName. Create
setDetails(String id,float salary,String companyName) to set the details of the
developer and override getData ()to print the details of Developer.
Create one more Subclass with name FullStackDeveloper that is getting inherited
from Developer class with instance variable technologyUsed.

Create setInfo(String technologyUsed) to set the details of FullStackDeveloper


.Override getData ()to print the details of FullStackDeveloper.

Finally create a class DeveloperDemo and inside main method create the object
of FullStackDeveloper class and call all the methods.(You can take hard coded
values)

Note: In getData() of all sub class use super keyword to call super class method
getData().

You might also like