You are on page 1of 2

1.

Create an interface Person that declares the function to calculate the age of the person and
inherit this to create a class CollegeGraduate. Add functionality to calculate Result of the
CollegeGraduate. Take data member accordingly.

2. Create a class Book in a package bookPack. Instantiate the object of book in a class
boookDemo. The bookDemo is in the package bookDemoPack.

3. Write a program that accepts two integer numbers through command line arguments.
Display the summation, subtraction, division and multiplication of them. Add Exception
Handling code for different Exceptions like Array index out of bound for wrong no of
arguments, Number format exception if an argument is not formatted as an integer,
Arithmetic exception for division by zero error, etc

4. The abstract class Animal has abstract subclasses named Bird and Reptile. Classes Dove,
Eagle, Hawk, Penguin and Seagull extend Bird. Classes Rattlesnake and Turtle extend
Reptile. The ColdBlooded interface defines no constants and declares no methods. It is
implemented by Reptile. The OceanDwelling interface also defines no constants and
declares no methods. It is implemented by the Penguin, Seagull and Turtle classes. Define
all of these classes and implement the interface as specified. Define an array of Animal and
create one instance of each class. Then display all ColdBooded animals and all
OceanDwelling animals.

5. Interface LuminousObject declares lightOff() and lightOn() methods. Class SolidObject


is extended by Cone and Cube. Class LuminousCone extends Cone and implements
LuminousObject. Class LuminousCube extends Cube and implements
LuminousObject. Instantiate the LuminousCone and LuminousCube classes. Use
interface reference to refer to those objects. Invoke the methods of the LuminousObject
interface via the interface reference.

6. A method named average has one argument that is an array of strings. It converts these to
double values and returns their average. The method generates a Null Pointer Exception, if
an array element is null or Number Format Exception if an element is incorrectly formatted.
Write a program that illustrates how to declare and use this method. Include a throws clause
in method declaration to indicate that these problems can occur.

7. The abstract class Animal has abstract subclasses named Bird and Reptile. Classes Dove,
Eagle, Hawk, Penguin and Seagull extend Bird. Classes Rattlesnake and Turtle extend
Reptile. The ColdBlooded interface defines no constants and declares no methods. It is
implemented by Reptile. The OceanDwelling interface also defines no constants and
declares no methods. It is implemented by the Penguin, Seagull and Turtle classes.
Define all of these classes and implement the interface as specified. Create one instance
of each class. Then display all ColdBooded animals and all OceanDwelling animals.

8. Write a program that illustrates method overriding. Class Bond is extended by


ConvertibleBond. Each of these classes defines a display() method that outputs the string
“Bond” or “ConvertibleBond”, respectively. Declare an array to hold six Bond objects.
Initialize the elements of the array with a mix of Bond and ConvertibleBond objects.
Execute a program loop to invoke the display() method of each object.

9. The abstract Airplane class has three subclasses named B747, B757 and B767. Each
airplane type can transport a different number of passengers. Each airplane object has a
unique serial number. Write an application that declares class hierarchy. Instantiate
several types of airplanes and display them. Override the toString() method of Object to
return a string with the type, serial number and capacity.

10. The abstract class Robot has concrete subclasses named RobotA, RobotB and RobotC.
Class RobotA1 extends RobotA. Classes RobotB1 and RobotB2 extend RobotB. Class
RobotC1 extends RobotC. The Locomotion interface declares three methods named
forward(), reverse() and stop(). It is implemented by classes RobotB and RobotC. The
Sound interface declares one method named beep(). It is implemented by classes
RobotA1, RobotB1 and RobotC. Define all of these classes and implement the interfaces
as specified. Create one instance of each class. Then invoke the beep() method of all
objects that are of type Sound. Also invoke the stop() method of all objects that are of
types Locomotion.

11. The abstract class Tent has concrete subclasses named TentA, TentB, TentC and TentD.
The Waterproof interface defines no constants and declares no methods. Implement it in
any two of above mentioned four classes. Define all of these classes, and implement the
interfaces as specified. Create one instance of each class. Then display all waterproof
tents. Place this code in a package named tents.

12. The abstract Fruit class has four subclasses named Apple, Banana, Orange and Strawberry.
Write an application that demonstrates how to establish this class hierarchy. Declare one
instance variable of type string that indicates the color of a fruit. Create and display
instances of these object. Override the toString() method of Object to return a string with
the name of the fruit and its color.

You might also like