Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Assignment on Abstract class, abstract method, super with

constructor
1) Create an abstract class Singer with instance variable singername, songtitle,
with abstract method void sing() and instance methods-
setData(String singername,String ongtitle) and getData()to set the values and
fetch the values. Create Two sub classes ClassicalSinger and PlayBackSinger,
in PlayBackSinger instance variable is filmname and instance method is
setDetails(String filmname) and in ClassicalSinger instance variable name is
instrumentname and instance method-
setDetails(String instrumentname).Create getData() methods in both the sub
classes to print the values and override sing()method in both the classes.
Create one more class SingerDemo and in main method create object of
ClassicalSinger and PlayBackSinger and call all the methods.

2) Create a class Worker with name,age as instance variable. Create only


parameterised constructor to initialise instance variable and printDetails() ,to
print the details of a worker. Make one abstract method calculateSalary() to
calculate the salary of worker .Create sub class DailyWageWorker with instance
variable noOfWorkingDays,constructionSiteName.
Create on parameterised constructor to initialise instance variable of super and
sub class both.

Override calculateSalary() to calculate total salary assuming that per day salary is
300Rs by making it constant. override printDetails() to get the details .

Finally create a WorkerDemo class and create object using parameterised


constructor of Worker class in main and call all the methods.
3) Create a class Furniture with instance variables color, price and material using
appropriate data types. Create one default and one parameterized constructor to
set the values and getData() to print details. Create one Subclass Table with
instance variable tabletype and nooflegs. Create on default and one
parameterized constructor in this subclass .Use super keyword to call super class
constructor from subclass for assigning values in super class instance variable.
Create getData method to print all the details. Create object of sub class and show
all the details of table.

Note: Here tabletype means (studytable ,Diningtable,computertable etc)

You might also like