Object Oriented Programming (Java)

Object Oriented Programming (July Oct 2018)



Object-oriented programming (OOP) is a programming paradigm that represents the concept of “objects” that have data fields (attributes that describe the object) and associated procedures known as methods.

This section briefly describe basic idea on class and Objects

Download01 Class and Objects


More Methods on a class

Constructor is a special type of subroutine called to create an object
Encapsulation is a language mechanism for restricting access to some of the object’s components
Composition is a way to combine simple objects or data types into more complex ones

Download:02 Advance Methods on class


Assignment #1


Sample Code: (This example demonstrates composition, constructors, methods… )



Object-oriented programming allows classes to inherit commonly used state and behavior from other classes

Download:03 Inheritance


Employee Example

employe example

Download: Complete Netbeans project (All classes: Date, Name, Employee, Temporary Employee, Manager, Contractor)


Video Tutorials

More Advance Object Oriented Programming concepts

Overriding, Abstraction, Packages, Polymopism

Download: 04 Advance Methods in OOP


Code Examples (Java classes)

Download: OOP Menu-driven Application development example


Exception Handling

Download : Exception Handling Note
File Handling

Download Lecturer Note (Files) [Download] 



Lab Activities

Lab Activity 1:

Bank Account Example

Create a menu driven Java application to handle Bank Account information. Class diagram of the system is given below.



  1. Complete each class
  2. Add menu for the application with following menu options
    • Add new Account
    • Deposit or withdraw amount
    • Get balance for the given account
    • Print all account information
    • Exit
  3. Test your application

Note that: each methods has it normal meaning

Lab Activity 2

Transport Example

“Jaffna Travels” is a pioneer transport service company in Sri Lanka. It provides transport services between Colombo and Jaffna. The management of the company requires to develop an online ticket booking system to reserve the seats in a given bus. Assume that, a bus consists of 50 seats. One passenger can book any number of seats. However, it depends on the seats availability at that time. The passengers are allowed to board into the bus only from Colombo, Jaffna, Anuradhapura and Vavuniya. The passengers who are boarded to the bus from Anuradhapura or Vavuniya have to pay 25% additional charge. However, there are no additional chargers for children (half ticket). The Table 1 shows the price of a ticket for a journey.


Table 1. Price of a ticket
Write a menu driven Java Application to complete the system
The class diagram for the proposed system is given in the below.



download 25 sample questions


%d bloggers like this: