Object Oriented Programming Exercises
Object Oriented Programming Exercises
Object Oriented Programming Exercises
Group Exercises
Date of Issue:
Due Date:
Question One
i)
ii)
Explain the role of static keyword in public static void main (String args[])?
iii)
iv)
Create a base class called shape. It contain two methods get xy value( ) show xy
value( ) for accept co-ordinates & to display the same. Create a subclass called
rectangle. It also contain a method to display the length & breadth as the rectangle
called show xy value( ) using overriding concept.
Question Two
i)
ii)
iii)
iv)
Create a class called car. Initialise the colour and the body to blue and wagon
respectively. There should be two constructors. One is the default constructor that
creates a blue wagon. The other constructor should take two arguments (colour and
body).
Question Three
i.
What is an exception? What are their types? Explain how user defined exception
clasess can be created
ii.
iii.
iv.
Create a class employee with data members employee (ID, employee name,
designation and salary) Write methods getEmployee( ) - To take user input,
showGrade( )- to display grade of employee based on salary, showEmployee( ) to
display employee details.
Question Four
a)
b)
c)
d)
What is the difference between static, final, finally and finalize () in Java
Identify and explain the the use of layout managers in Java
What is difference between overriding and overloading a method?
Write a program that has an overloaded method. The first method should accept no
arguments the second method will accept one string & the third method will accept a
string & an integer. The first method should display the message welcome to java
once. The second method should display the message welcome to polymorphism
twice & the third method should display the message welcome to overloading three
times.
Question Five
Sarova Whitesand Hotel in Mombasa is giving seasonal discount on the total amount to be
paid by the person staying at the time of check out. The charge for one day stay is Kshs
5,000.00 per room. The discount will be given as per the following criteria:
Up to 5 days
10 %
15 %
20 %
25 %
Required:
Write a java program that will:
a) Input name of guest, total number of days stayed in the hotel.
b) Calculate the total amount to be paid and the discount amount.
c) Find the net balance to be paid excluding the discount.
Question Six
a) What is the use of the keyword Super in Java
b) Differentiate between a constructor and a method.
c) Define a Student class (roll number, name, percentage). Define a default and
parameterized constructor. Create objects using parameterized constructor and display
the object count after each object is created. (Use static member and method). Also
display the contents of each object.
d) Write a Java application that determines and prints the number of odd, even and zero
digits in the array.
Question Seven
a) Explain the difference between AWT & Swing components
b) Explain the following classes:
i.
JFrame
ii.
JList
iii.
JLable
iv.
JTextField
v.
JTextArea