OOP Worksheet
OOP Worksheet
Worksheet
4. How can we bring abstraction in Object Oriented Programming? (Explain in detail about
abstract classes, Interfaces, and their differences with examples )
7. How will a class that implements an Interface but doesn’t write implementation for all of the
interface’s abstract methods be treated by java?
9. In java a class may extend only one class but can implement multiple interfaces. Write a
program to demonstrate such a case.
10. Polymorphism can be brought about via inheritance, method overloading, method overriding ..
among others. Explain each of the above scenarios with an example.
11. Explain method overriding and its difference with method overloading (with examples).
12. Design a relational database and develop a java program that keeps track of all students in a
department and stores the data in a MySQL relation called student. Add any constructor,
getter, and setter methods that you deem relevant for the project. The project should be a GUI
application.
Classes
Student
Department
- id: int
- fname: String
- id: int
- lname: String
- name: String
- dob: String
- location: String
- dept: int
+ changeName(): void
+ getStudentData(): Student
+ changeLocation(): void
+ changeName(): void
+ getDepartmentData: Department
+ changeDept(): void
13. Consider the problem in question 4 and assume that there is another Class called “Person”
that acts as a superclass to the “Student” class described above and an “Employee” class.
Attributes and operations that are common to them should be sent to the “Person” class.
Remodel the problem above to incorporate Person and Employee classes. Add any attributes,
operations, constructors, getter and setter methods that you deem relevant for the problem.
14. Write an abstract class “Age” that contains an abstract method “getAge(): int”. This abstract
method should be inherited by “Student” and “Employee” and should return the age of an
object from the “date of birth (dob)” attribute that is defined.
15. Change the abstract class “Age” to an interface and understand its difference with question
14.