OBJECT ORIENTED
Hasanka Wijesinghe
PROGRAMMING
MIT, B.Sc
Programming Design Techniques and Programming
Content
Class and Methods
Access Modifiers
Object Oriented Concepts
DSE004 Hasanka Wijesinghe
Java Class and Methods
DSE004 Hasanka Wijesinghe
Java Methods
DSE004 Hasanka Wijesinghe
Method type
Methods with return type
Methods without return type
Methods with return type Methods without return type
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
Access Modifiers
DSE004 Hasanka Wijesinghe
Public
The most permissive access level.
Public members are accessible from any other class.
Access Modifiers
DSE004 Hasanka Wijesinghe
Private
The most restrictive access level.
Private members are only accessible within the same class.
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
DSE004 Hasanka Wijesinghe
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
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
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
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
Inheritance
DSE004 Hasanka Wijesinghe
Super Class / Parent Class
Sub Class / Child Class
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
Polymorphism
DSE004 Hasanka Wijesinghe
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
Abstraction
DSE004 Hasanka Wijesinghe
THANK YOU!
DSE004 Hasanka Wijesinghe

Object Oriented Programming CONCEPTS.pdf

  • 1.
    OBJECT ORIENTED Hasanka Wijesinghe PROGRAMMING MIT,B.Sc Programming Design Techniques and Programming
  • 2.
    Content Class and Methods AccessModifiers Object Oriented Concepts DSE004 Hasanka Wijesinghe
  • 3.
    Java Class andMethods DSE004 Hasanka Wijesinghe
  • 4.
    Java Methods DSE004 HasankaWijesinghe Method type Methods with return type Methods without return type Methods with return type Methods without return type
  • 5.
    Java Object Creation DSE004Hasanka 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 HasankaWijesinghe Public The most permissive access level. Public members are accessible from any other class.
  • 7.
    Access Modifiers DSE004 HasankaWijesinghe Private The most restrictive access level. Private members are only accessible within the same class.
  • 8.
    Protected Members are accessiblewithin 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
  • 9.
  • 10.
    Object Oriented ProgrammingConcepts 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 away 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 classrepresenting 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 amechanism 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
  • 14.
    Inheritance DSE004 Hasanka Wijesinghe SuperClass / Parent Class Sub Class / Child Class
  • 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
  • 16.
  • 17.
    Abstraction involves simplifyingcomplex 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
  • 18.
  • 19.