[go: up one dir, main page]

0% found this document useful (0 votes)
51 views2 pages

OOPJ - Practical Assignment-I PDF

This document contains 7 programming assignments involving object-oriented concepts in Java: 1. Define an Employee class with subclasses for Salary details. Include constructors, methods to find high earners, and a main method. 2. Design a Fan class with constants for speeds, fields for status and details, constructors, and a display method to show fan descriptions. 3. Define an Animal class with subclasses implementing a Transport interface. The interface declares a delivery method to be invoked. 4. Create a Vegetable class hierarchy with subclasses for types. Override toString to return name and color. 5. Define an abstract Shape class with subclasses for types. Override an area method in each subclass.

Uploaded by

Mihir Panchal
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)
51 views2 pages

OOPJ - Practical Assignment-I PDF

This document contains 7 programming assignments involving object-oriented concepts in Java: 1. Define an Employee class with subclasses for Salary details. Include constructors, methods to find high earners, and a main method. 2. Design a Fan class with constants for speeds, fields for status and details, constructors, and a display method to show fan descriptions. 3. Define an Animal class with subclasses implementing a Transport interface. The interface declares a delivery method to be invoked. 4. Create a Vegetable class hierarchy with subclasses for types. Override toString to return name and color. 5. Define an abstract Shape class with subclasses for types. Override an area method in each subclass.

Uploaded by

Mihir Panchal
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/ 2

Department of Computer Engineering

Subject: OOPJ
Assignment-I
1. Declare a class called employee having employee_id and employee_name as members.
Extend class employee to have a subclass called salary having designation and
monthly_salary as embers. Define following:
- Required constructors
- A method to find and display all details of employees drawing salary more than Rs. 20000/-
- Method main for creating an array for storing these details given as command line
arguments and showing usage of above methods.

2. Design a class named Fan to represent a fan. The class contains:


- Three constants named LOW, MEDIUM and FAST with values 1,2 and 3 to denote the fan
speed.
- An int data field named speed that specifies the speed of the fan (default SLOW).
- A boolean data field named f_on that specifies whether the fan is on(defaultfalse).
- A double data field named radius that specifies the radius of the fan (default 4).
- A data field named color that specifies the color of the fan (default blue).
- A no-arg constructor that creates a default fan.
- A parameterized constructor initializes the fan objects to given values.
- A method named display() will display description for the fan. If the fan is on, the display()
method displays speed, color and radius. If the fan is not on, the method returns fan color and
radius along with the message “fan is off”. Write a test program that creates two Fan objects.
One with default values and the other with medium speed, radius 6, color brown, and turned
on status true. Display the descriptions for two created Fan objects.

3. The Transport interface declares a deliver() method. The abstract class Animal is the
superclass of the Tiger, Camel, Deer and Donkey classes. The Transport interface is
implemented by the Camel and Donkey classes. Write a test program that initialize an array
of four Animal objects. If the object implements the Transport interface, the deliver() method
is invoked.

4. The abstract Vegetable class has three subclasses named Potato, Brinjal and Tomato. Write
an application that demonstrates how to establish this class hierarchy. Declare one instance
variable of type String that indicates the color of a vegetable. Create and display instances of
these objects. Override the toString() method of Object to return a string with the name of the
vegetable and its color.

5. Describe abstract class called Shape which has three subclasses say Triangle, Rectangle,
Circle. Define one method area() in the abstract class and override this area() in these three
subclasses to calculate for specific object i.e. area() of Triangle subclass should calculate area
of triangle etc. Same for Rectangle and Circle.
6. Declare a class called book having author_name as private data member. Extend book class to
have two sub classes called book_publication & paper_publication. Each of these classes have
private member called title. Write a complete program to show usage of dynamic method
dispatch (dynamic polymorphism) to display book or paper publications of given author. Use
command line arguments for inputting data.

7. Write a program that illustrates interface inheritance. Interface A is extended by A1 and A2.
Interface A12 inherits from both P1 and P2.Each interface declares one constant and one
method. Class B implements A12.Instantiate B and invoke each of its methods. Each method
displays one of the constants.

You might also like