[go: up one dir, main page]

0% found this document useful (0 votes)
26 views1 page

Batch 7days2

The document provides questions to practice OOP concepts in Java including inheritance, method overriding, and method overloading. Question 1 involves creating parent and child classes with methods. Question 2 creates classes for employees and managers that inherit from a base member class. Question 3 creates rectangle and square classes that demonstrate inheritance and constructor calls. Question 4 demonstrates initializing and looping through a string array. Question 5 involves creating a calculator class with addition and subtraction methods to demonstrate method overloading.

Uploaded by

Shivam Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

Batch 7days2

The document provides questions to practice OOP concepts in Java including inheritance, method overriding, and method overloading. Question 1 involves creating parent and child classes with methods. Question 2 creates classes for employees and managers that inherit from a base member class. Question 3 creates rectangle and square classes that demonstrate inheritance and constructor calls. Question 4 demonstrates initializing and looping through a string array. Question 5 involves creating a calculator class with addition and subtraction methods to demonstrate method overloading.

Uploaded by

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

Day 2

Hands on practice
Question 1
Create a class with a method that prints "This is parent class" and its subclass with another
method that prints "This is child class". Now, create an object for each of the class and call
1 - method of parent class by object of parent class
2 - method of child class by object of child class
3 - method of parent class by object of child class

Question 2
Create a class named 'Member' having the following members:
Data members
1 - Name
2 - Age
3 - Phone number
4 - Address
5 - Salary
It also has a method named 'printSalary' which prints the salary of the members.
Two classes 'Employee' and 'Manager' inherits the 'Member' class. The 'Employee' and
'Manager' classes have data members 'specialization' and 'department' respectively. Now,
assign name, age, phone number, address and salary to an employee and a manager by
making an object of both of these classes and print the same.

Question 3
Create a class named 'Rectangle' with two data members 'length' and 'breadth' and two
methods to print the area and perimeter of the rectangle respectively. Its constructor having
parameters for length and breadth is used to initialize length and breadth of the rectangle.
Let class 'Square' inherit the 'Rectangle' class with its constructor having a parameter for its
side (suppose s) calling the constructor of its parent class as 'super(s,s)'. Print the area and
perimeter of a rectangle and a square.

Question 4

- a) Write a statement that declares a string array initialized with the following strings:
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" and "Saturday".
b) Write a loop that displays the contents of each element in the array that you declared.

Question 5

Create a class calculator where mention addition subtraction methods that can explain the method
overloading feature .

You might also like