4. Java Methods
DSE004 Hasanka Wijesinghe
Method type
Methods with return type
Methods without return type
Methods with return type Methods without return type
5. Java Object Creation
DSE004 Hasanka Wijesinghe
In Java, objects are instances of classes, and you create objects using the new keyword
along with a constructor.
Class
Object
6. Access Modifiers
DSE004 Hasanka Wijesinghe
Public
The most permissive access level.
Public members are accessible from any other class.
7. Access Modifiers
DSE004 Hasanka Wijesinghe
Private
The most restrictive access level.
Private members are only accessible within the same class.
8. Protected
Members are accessible within the same class, subclass (even if the subclass is in a
different package), and package.
Not accessible outside the package unless there is an inheritance relationship.
Access Modifiers
DSE004 Hasanka Wijesinghe
10. Object Oriented Programming Concepts
Encapsulation
Encapsulation is the bundling of data and
methods that operate on the data into a
single unit known as a class.
Polymorphism
Polymorphism means "many forms" and
refers to the ability of objects to take on
multiple forms.
Inheritance
Inheritance is a mechanism that allows a
class to inherit properties and behaviors
from another class
Abstraction
Abstraction is the process of simplifying
complex systems by modeling classes based
on the essential properties and behaviors they
possess.
DSE004 Hasanka Wijesinghe
11. Encapsulation is a way to restrict the direct access to some components of an object
Encapsulation can be used to hide both data members and data functions or
methods associated with an instantiated class or object.
Encapsulation
DSE004 Hasanka Wijesinghe
12. Consider a class representing a bank account. Apply encapsulation principles to
design the class with private attributes such as account number, balance, and owner's
name. Provide public methods to deposit and withdraw funds while ensuring that the
balance cannot be accessed or modified directly. Demonstrate the usage of
encapsulation in your solution.
Encapsulation
DSE004 Hasanka Wijesinghe
13. Inheritance is a mechanism that allows a
class (subclass or derived class) to inherit
properties and behaviors from another class
(superclass or base class).
It promotes code reuse and establishes a
relationship between classes, facilitating the
creation of a hierarchical structure.
Inheritance
DSE004 Hasanka Wijesinghe
15. In object-oriented programming (OOP), polymorphism is the concept
that an entity in code can have more than one form.
In Java, polymorphism is achieved through method overloading and
method overriding.
Method Overloading: Multiple methods with the same name but
different parameter lists.
Method Overriding: A subclass provides a specific implementation of
a method that is already defined in its superclass.
Polymorphism
DSE004 Hasanka Wijesinghe
17. Abstraction involves simplifying complex systems by modeling classes based on the
essential properties and behaviors they possess.
Abstraction can create a clear separation between the interface (what the object does)
and the implementation (how it does it). This separation enhances modularity, making
it easier to maintain and update the system.
It helps break down a large, complex problem into smaller, more manageable
components.
Abstraction
DSE004 Hasanka Wijesinghe