0% found this document useful (0 votes)
113 views

OOP Worksheet

The document contains 15 questions about object-oriented programming concepts like encapsulation, abstraction, inheritance, and polymorphism. It asks the reader to explain these concepts, provide examples demonstrating them, and design classes and relationships between classes to model problems involving students, departments, and other entities. It also asks the reader to incorporate superclass-subclass relationships and interfaces into class designs.

Uploaded by

sender
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)
113 views

OOP Worksheet

The document contains 15 questions about object-oriented programming concepts like encapsulation, abstraction, inheritance, and polymorphism. It asks the reader to explain these concepts, provide examples demonstrating them, and design classes and relationships between classes to model problems involving students, departments, and other entities. It also asks the reader to incorporate superclass-subclass relationships and interfaces into class designs.

Uploaded by

sender
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

Addis Ababa University Department of Computer Science

Object Oriented Programming

Worksheet

Focus on the pillars of OOP: Encapsulation, Abstraction, Inheritance, Polymorphism


1. Look at the worksheet questions on: https://www.cs.usfca.edu/~parrt/course/601/
worksheets/oo.html and answer them.

2. Explain how OOP is different from structured programming?

3. What is the main purpose of Encapsulation? explain this with an example.

4. How can we bring abstraction in Object Oriented Programming? (Explain in detail about
abstract classes, Interfaces, and their differences with examples )

5. How can you prevent a class from being inherited?

6. How can we prevent an attribute/s of a class from being inherited by a subclass?

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?

8. May an Inheritance relationship exist between interfaces? (explain with an example)

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.

You might also like