Exercise - Lab 5: (Due Date – 15 – 10 -2022)
1. Define a class named Course having data members ID, Description, Duration and
Fees. The class should have one parametrized constructors and GetData() function
member to display the data.
-Create an array of 5 course objects and then display the data for all of them.
2. Modify program 1 to add a default constructor and a SetData() member
function.
-Create an array of 3 student using the default constructor and another
array of 2 students using the parametrized constructor, and then display the
data of all 5 course objects.
3. Write a program to define constructors and finalize of a class and construct
3 objects and then show that it is not a guarantee that finalizer will be
invoked for each object.
4. Write a program to demonstrate the use of final keyword with
a) class
b) method
c) data member (primitive value and reference variable and show that you
cannot refer this reference variable to other objects but can change the data
field of a final reference variable)
5. write a program to demonstrate the use of following operators.
a) right shift with sign bit operator >>
b) left shift operator <<
c)right shift with zero fill operator >>>
6. write a program to demonstrate
a) Labeled break
b) Labeled continue
7. Demonstrate the use of ‘this’ keyword
a) To refer to current object.
b) Inside a constructor to call another constructor.
And also show that this cannot be used in static context area.
8. Demonstrate the use of ‘super’ keyword.
a) To refer to a member of super class.
b) To call super class constructor from sub class constructor.
9. Write a program to make a request to invoke garbage collector
10. Write a program to demonstrate the use of nested class and its objects when
nested class is a
a) private member of the outer class
b) public member of the outer class.
11. Define a base class person and a derived class employee with single inheritance.
-Define SetData() member functions in each of the class with different signatures to set the data
members and demonstrate overloading of member functions.
-Define GetData() member functions in each of the class with same signatures to display data and
demonstrate overriding of member functions.
12. Modify program 11 to define a parametrized constructor and finalizer in each class.
Demonstrate calling the constructor of the base class from the constructor of the derived class.
Create objects of person and employee classes to show the order of invocation of constructors.
13. Modify program 12 to define another class manager that derives from employee, to create a chain of
multilevel
hierarchy. (manager inherits from employee & employee inherits from person)
-Create objects of person, employee, and manager classes to show the order of invocation of
constructors.
14. Modify program 12 to define another class student that derives from person, to create a hierarchial
inheritance. (employee and student inherit from person)
-Create objects of person, employee, and student classes to show the order of invocation of
constructors.
15. Write a java file [Link] containing definition of independent class Person in package
[Link],
and another java file [Link] containing definition of independent class Address in [Link]
package.
-Write a container class employee that has a person and an address object as contained data
members (besides other data members) by importing the above packages.
-Demonstrate the passing of arguments in the constructors of person and address classes by the
constructor of the employee class.
16. Rework program 5 to use both inheritance and containership. The employee class inherits from
person
class and acts as a container class for address class object.
17. Write a program to demonstrate the use of try, catch, finally throw and throws keywords and
demonstrate
the following points in the program.
a) Multiple catch blocks.
b) try-catch-finally combination.
c) try-finally combination.
d) Exception propagation among many methods.
e) Use of getMessage(), printStackTrace() function of Throwable class.
f) Nested try blocks
18. Write a program to throw a checked exception explicitly using 'throw' keyword and
a) Handle the exception in same method.
b) use throws clause and handle the exception in some other method (calling method)
c) Don't either handle or use the throws clause. Observe the result.
19. Repeat program 8 with unchecked Exception and demonstrate the difference in both programs.
20. Create a user defined exception to check whether your employee exist in your data structure (use
any data structure to store the employees -like array, ArrayList etc) and throw exception if name is not
in the employees list. Use the catch and finally block to make an appropriate solution.
21. Write a program to demonstrate the use of equals method of Object class and compare its
functionality with ( = = ) operator.
22. Modify program 1 with Integer class Object. Use the override equals method of Integer with two
different object wrapping same primitive int value
23. Demonstrate the use of ceil(), floor(), round(), random(), abs(), max(), min() methods of Math class.
24. Write a program to invoke garbage collector and show the details of free memory before and after
the garbage collection.
25. Write a program to print all System properties using system class.
26. Define a method setMyProperty (String, String) to set your own system property and use the same
system property in another method.