Q no .
1 Create the following three classes:
• Restaurant (Super Class):
Instance variables: name and address
Parameterized Constructor with name and address as parameters.
Assign the parameter’s value in instance variable using this
keyword
display() – prints all the values
• MyRestro (Sub Class):
Instance variable – offer
Parameterized Constructor with name, address and offer as
parameters.
Call super constructor by passing name and address
Assign the value of offer in instance variable using this
keyword
display()
call super class’s super method
print the value of offer
• OurRestro(Sub Class)
Parameterized Constructor with name and address as parameters.
Call super constructor by passing name and address
Ans))
here , I have created object of MyRestro and then call the display() method. Also, I
have created an object of OurRestro and call display() method to show the output.
Q no 2)) Create the following two classes:
Employee (Super class):
Instance variable: name and salary
Parameterized Constructor with name and salary as parameters.
Assign the parameter’s value in instance variable using this
keyword
show() – prints the name and salary
Programmer (Sub class):
Instance variable – bonus and progLanguage
Parameterized constructor with name, salary, bonus and progLanguage
as parameters
Using super keyword call parent constructor by passing name and
salary in parameter
Assign the bonus and progLanguage values in instance variable
using this keyword
show ()
Using super keyword call parent’s show () method
Print the bonus and progLanguage
Using BlueJ, create an object of Programmer and then call show() method.
Ans))
Here, in the screenshot above I have created an object of Programmer and then call
show() method to view the output.