0% found this document useful (0 votes)
19 views5 pages

Bhimsen Sharma C4.week6

The document outlines the creation of two sets of classes in Java: 'Restaurant' as a superclass with a subclass 'MyRestro' that includes an offer, and another subclass 'OurRestro'. It also describes an 'Employee' superclass with a 'Programmer' subclass that includes bonus and programming language attributes. The document includes instructions for displaying the values of these classes through their respective methods.

Uploaded by

Anjal Mahato
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Bhimsen Sharma C4.week6

The document outlines the creation of two sets of classes in Java: 'Restaurant' as a superclass with a subclass 'MyRestro' that includes an offer, and another subclass 'OurRestro'. It also describes an 'Employee' superclass with a 'Programmer' subclass that includes bonus and programming language attributes. The document includes instructions for displaying the values of these classes through their respective methods.

Uploaded by

Anjal Mahato
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

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.

You might also like