SlideShare a Scribd company logo
1 of 30
OOP Concepts
Eng. Ahmed Farag
Object-oriented programming
• Object-oriented programming System(OOPs) is a programming
paradigm based on the concept of “objects” that contain data and
methods.
• The primary purpose of object-oriented programming is to increase
the flexibility and maintainability of programs.
• Object oriented programming brings together data and its
behavior(methods) in a single location(object) makes it easier to
understand how a program works.
What is an Object?
• Object: is a bundle of data and its behavior (often known as
methods).
• Objects have two characteristics: They have states and behaviors.
• Examples of states and behaviors
Example 1: Example 2:
Object: House Object: Car
State: Address, Color, Area State: Color, Brand, Weight, Model
Behavior: Open door, close door Behavior: Break, Accelerate, Slow Down,
Gear change.
What is an Object? Con…
class House {
String address;
String color;
double area;
void openDoor() {
//Write code here
}
void closeDoor() {
//Write code here
}
... ...
}
Object Oriented Programming features
Abstraction Encapsulation
Inheritance Polymorphism
Abstraction
• One of the most fundamental concept of OOPs is Abstraction.
• Abstraction is a process where you show only “relevant” data and
“hide” unnecessary details of an object from the user.
• For example:
• when you login to your Amazon account online, you enter your
user_id and password and press login, what happens when you
press login, how the input data sent to amazon server, how it gets
verified is all abstracted away from the you.
Abstraction Con…
• Another example of abstraction:
• A car in itself is a well-defined object, which is composed of several other
smaller objects like a gearing system, steering mechanism, engine, which are
again have their own subsystems. But for humans car is a one single object,
which can be managed by the help of its subsystems, even if their inner
details are unknown.
Object Oriented Programming features
Abstraction Encapsulation
Inheritance Polymorphism
Encapsulation
• Encapsulation simply means binding object state(fields) and
behavior(methods) together. If you are creating class, you are doing
encapsulation.
• Encapsulation is:
• Binding the data with the code that manipulates it.
• It keeps the data and the code safe from external interference
Encapsulation Con…
• The whole idea behind encapsulation is to hide the implementation
details from users. If a data member is private it means it can only be
accessed within the same class. No outside class can access private
data member (variable) of other class.
• However if we setup public getter and setter methods to update (for
example void setSSN(int ssn))and read (for example int getSSN()) the private
data fields then the outside class can access those private data fields
via public methods.
Encapsulation Con…
• This way data can only be accessed by public methods thus making
the private fields and their implementation hidden for outside
classes. That’s why encapsulation is known as data hiding.
Encapsulation Con…
• Example of Encapsulation in Java
• How to implement encapsulation in java:
1. Make the instance variables private so that they cannot be
accessed directly from outside the class. You can only set and
get values of these variables through the methods of the class.
2. Have getter and setter methods in the class to set and get the
values of the fields.
Encapsulation Con…
• A example of encapsulation is the class of java.util.Hashtable. User
only knows that he can store data in the form of key/value pair in a
Hashtable and that he can retrieve that data in the various ways. But
the actual implementation like, how and where this data is actually
stored, is hidden from the user. User can simply use Hashtable
wherever he wants to store Key/Value pairs without bothering about
its implementation.
Encapsulation Demo
• Demo using Java
Advantages of encapsulation
• It improves maintainability and flexibility.
• The fields can be made read-only.
• User would not be knowing what is going on behind the scene. They
would only be knowing that to update a field call set method and to
read a field call get method but what these set and get methods are
doing is purely hidden from them.
Object Oriented Programming features
Abstraction Encapsulation
Inheritance Polymorphism
Inheritance
• Inheritance is the mechanism by which an object acquires the
some/all properties of another object.
• The process by which one class acquires the properties(data
members) and functionalities(methods) of another class is called
inheritance.
Inheritance
• The aim of inheritance is to provide the reusability of code so that a
class has to write only the unique features and rest of the common
properties and functionalities can be extended from the another
class.
Inheritance
• Inheritance is a process of defining a new class based on an existing
class by extending its common data members and methods.
• Inheritance allows us to reuse of code, it improves reusability in your
java application.
• Note: The biggest advantage of Inheritance is that the code that is
already present in base class need not be rewritten in the child class.
Child and Base Class
• Child Class:
• The class that extends the features of another class is known as child class,
sub class or derived class.
• Parent Class:
• The class whose properties and functionalities are used(inherited) by
another class is known as parent class, super class or Base class.
• Note: The derived class inherits all the members and methods that
are declared as public or protected.
Inheritance Demo
• Demo using Java
Types of inheritance
• Single Inheritance: refers to a child and parent class relationship where a
class extends the another class.
• Multilevel inheritance: refers to a child and parent class relationship where
a class extends the child class. For example class C extends class B and class
B extends class A.
• Hierarchical inheritance: refers to a child and parent class relationship
where more than one classes extends the same class. For example, classes
B, C & D extends the same class A.
• Multiple Inheritance: refers to the concept of one class extending more
than one classes, which means a child class has two parent classes. For
example class C extends both classes A and B. Java doesn’t support
multiple inheritance
Constructors and Inheritance
• Constructor of sub class is invoked when we create the object of
subclass, it by default invokes the default constructor of super class.
Hence, in inheritance the objects are constructed top-down.
• The superclass constructor can be called explicitly using the super
keyword, but it should be first statement in a constructor.
• Example in java (Demo)
Object Oriented Programming features
Abstraction Encapsulation
Inheritance Polymorphism
Polymorphism
• Polymorphism is one of the OOPs feature that allows us to perform a
single action in different ways.
• Polymorphism is the capability of a method to do different things
based on the object that it is acting upon. In other words,
polymorphism allows you define one interface and have multiple
implementations.
Polymorphism
• In other words it means, one method with multiple implementation,
for a certain class of action. And which implementation to be used is
decided at runtime depending upon the situation (i.e., data type of
the object)
Static and Dynamic Polymorphism
• Polymorphism could be static and dynamic both.
• Method Overloading is static polymorphism while, Method
overriding is dynamic polymorphism.
Static Polymorphism
• Overloading in simple words means more than one method having
the same method name that behaves differently based on the
arguments passed while calling the method.
• This called static because, which method to be invoked is decided at
the time of compilation.(compile time)
Dynamic Polymorphism
• Overriding means a derived class is implementing a method of its
super class. The call to overridden method is resolved at runtime,
thus called runtime polymorphism
Polymorphism
• Demo

More Related Content

What's hot

Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
Kumar
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programmingthe Concept of Object-Oriented Programming
the Concept of Object-Oriented Programming
Aida Ramlan II
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
daxesh chauhan
 

What's hot (20)

Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#
 
Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
 
OOP java
OOP javaOOP java
OOP java
 
Oops
OopsOops
Oops
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Oop
OopOop
Oop
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programmingthe Concept of Object-Oriented Programming
the Concept of Object-Oriented Programming
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
Object Oriented Programming ppt presentation
Object Oriented Programming ppt presentationObject Oriented Programming ppt presentation
Object Oriented Programming ppt presentation
 
[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)
 
Basic oop concepts - C++
Basic oop concepts - C++Basic oop concepts - C++
Basic oop concepts - C++
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Oop java
Oop javaOop java
Oop java
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 

Similar to Introduction to OOP concepts

Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 

Similar to Introduction to OOP concepts (20)

Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwords
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
 
Principles of OOPs.pptx
Principles of OOPs.pptxPrinciples of OOPs.pptx
Principles of OOPs.pptx
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
 
Questpond - Top 10 Interview Questions and Answers on OOPS
Questpond - Top 10 Interview Questions and Answers on OOPSQuestpond - Top 10 Interview Questions and Answers on OOPS
Questpond - Top 10 Interview Questions and Answers on OOPS
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
Cs2305 programming paradigms lecturer notes
Cs2305   programming paradigms lecturer notesCs2305   programming paradigms lecturer notes
Cs2305 programming paradigms lecturer notes
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)
 
80410172053.pdf
80410172053.pdf80410172053.pdf
80410172053.pdf
 
Object Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxObject Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptx
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 

More from Ahmed Farag (14)

Intro to php
Intro to phpIntro to php
Intro to php
 
MYSql manage db
MYSql manage dbMYSql manage db
MYSql manage db
 
Normalization
NormalizationNormalization
Normalization
 
Sql modifying data - MYSQL part I
Sql modifying data - MYSQL part ISql modifying data - MYSQL part I
Sql modifying data - MYSQL part I
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operators
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-having
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDB
 
Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
OOP C++
OOP C++OOP C++
OOP C++
 
Functions C++
Functions C++Functions C++
Functions C++
 
intro to pointer C++
intro to  pointer C++intro to  pointer C++
intro to pointer C++
 
Intro to C++
Intro to C++Intro to C++
Intro to C++
 

Recently uploaded

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Introduction to OOP concepts

  • 2. Object-oriented programming • Object-oriented programming System(OOPs) is a programming paradigm based on the concept of “objects” that contain data and methods. • The primary purpose of object-oriented programming is to increase the flexibility and maintainability of programs. • Object oriented programming brings together data and its behavior(methods) in a single location(object) makes it easier to understand how a program works.
  • 3. What is an Object? • Object: is a bundle of data and its behavior (often known as methods). • Objects have two characteristics: They have states and behaviors. • Examples of states and behaviors Example 1: Example 2: Object: House Object: Car State: Address, Color, Area State: Color, Brand, Weight, Model Behavior: Open door, close door Behavior: Break, Accelerate, Slow Down, Gear change.
  • 4. What is an Object? Con… class House { String address; String color; double area; void openDoor() { //Write code here } void closeDoor() { //Write code here } ... ... }
  • 5. Object Oriented Programming features Abstraction Encapsulation Inheritance Polymorphism
  • 6. Abstraction • One of the most fundamental concept of OOPs is Abstraction. • Abstraction is a process where you show only “relevant” data and “hide” unnecessary details of an object from the user. • For example: • when you login to your Amazon account online, you enter your user_id and password and press login, what happens when you press login, how the input data sent to amazon server, how it gets verified is all abstracted away from the you.
  • 7. Abstraction Con… • Another example of abstraction: • A car in itself is a well-defined object, which is composed of several other smaller objects like a gearing system, steering mechanism, engine, which are again have their own subsystems. But for humans car is a one single object, which can be managed by the help of its subsystems, even if their inner details are unknown.
  • 8. Object Oriented Programming features Abstraction Encapsulation Inheritance Polymorphism
  • 9. Encapsulation • Encapsulation simply means binding object state(fields) and behavior(methods) together. If you are creating class, you are doing encapsulation. • Encapsulation is: • Binding the data with the code that manipulates it. • It keeps the data and the code safe from external interference
  • 10. Encapsulation Con… • The whole idea behind encapsulation is to hide the implementation details from users. If a data member is private it means it can only be accessed within the same class. No outside class can access private data member (variable) of other class. • However if we setup public getter and setter methods to update (for example void setSSN(int ssn))and read (for example int getSSN()) the private data fields then the outside class can access those private data fields via public methods.
  • 11. Encapsulation Con… • This way data can only be accessed by public methods thus making the private fields and their implementation hidden for outside classes. That’s why encapsulation is known as data hiding.
  • 12. Encapsulation Con… • Example of Encapsulation in Java • How to implement encapsulation in java: 1. Make the instance variables private so that they cannot be accessed directly from outside the class. You can only set and get values of these variables through the methods of the class. 2. Have getter and setter methods in the class to set and get the values of the fields.
  • 13. Encapsulation Con… • A example of encapsulation is the class of java.util.Hashtable. User only knows that he can store data in the form of key/value pair in a Hashtable and that he can retrieve that data in the various ways. But the actual implementation like, how and where this data is actually stored, is hidden from the user. User can simply use Hashtable wherever he wants to store Key/Value pairs without bothering about its implementation.
  • 15. Advantages of encapsulation • It improves maintainability and flexibility. • The fields can be made read-only. • User would not be knowing what is going on behind the scene. They would only be knowing that to update a field call set method and to read a field call get method but what these set and get methods are doing is purely hidden from them.
  • 16. Object Oriented Programming features Abstraction Encapsulation Inheritance Polymorphism
  • 17. Inheritance • Inheritance is the mechanism by which an object acquires the some/all properties of another object. • The process by which one class acquires the properties(data members) and functionalities(methods) of another class is called inheritance.
  • 18. Inheritance • The aim of inheritance is to provide the reusability of code so that a class has to write only the unique features and rest of the common properties and functionalities can be extended from the another class.
  • 19. Inheritance • Inheritance is a process of defining a new class based on an existing class by extending its common data members and methods. • Inheritance allows us to reuse of code, it improves reusability in your java application. • Note: The biggest advantage of Inheritance is that the code that is already present in base class need not be rewritten in the child class.
  • 20. Child and Base Class • Child Class: • The class that extends the features of another class is known as child class, sub class or derived class. • Parent Class: • The class whose properties and functionalities are used(inherited) by another class is known as parent class, super class or Base class. • Note: The derived class inherits all the members and methods that are declared as public or protected.
  • 22. Types of inheritance • Single Inheritance: refers to a child and parent class relationship where a class extends the another class. • Multilevel inheritance: refers to a child and parent class relationship where a class extends the child class. For example class C extends class B and class B extends class A. • Hierarchical inheritance: refers to a child and parent class relationship where more than one classes extends the same class. For example, classes B, C & D extends the same class A. • Multiple Inheritance: refers to the concept of one class extending more than one classes, which means a child class has two parent classes. For example class C extends both classes A and B. Java doesn’t support multiple inheritance
  • 23. Constructors and Inheritance • Constructor of sub class is invoked when we create the object of subclass, it by default invokes the default constructor of super class. Hence, in inheritance the objects are constructed top-down. • The superclass constructor can be called explicitly using the super keyword, but it should be first statement in a constructor. • Example in java (Demo)
  • 24. Object Oriented Programming features Abstraction Encapsulation Inheritance Polymorphism
  • 25. Polymorphism • Polymorphism is one of the OOPs feature that allows us to perform a single action in different ways. • Polymorphism is the capability of a method to do different things based on the object that it is acting upon. In other words, polymorphism allows you define one interface and have multiple implementations.
  • 26. Polymorphism • In other words it means, one method with multiple implementation, for a certain class of action. And which implementation to be used is decided at runtime depending upon the situation (i.e., data type of the object)
  • 27. Static and Dynamic Polymorphism • Polymorphism could be static and dynamic both. • Method Overloading is static polymorphism while, Method overriding is dynamic polymorphism.
  • 28. Static Polymorphism • Overloading in simple words means more than one method having the same method name that behaves differently based on the arguments passed while calling the method. • This called static because, which method to be invoked is decided at the time of compilation.(compile time)
  • 29. Dynamic Polymorphism • Overriding means a derived class is implementing a method of its super class. The call to overridden method is resolved at runtime, thus called runtime polymorphism

Editor's Notes

  1. It improves maintainability and flexibility and re-usability: for e.g. In the above code the implementation code of void setEmpName(String name) and String getEmpName() can be changed at any point of time. Since the implementation is purely hidden for outside classes they would still be accessing the private field empName using the same methods (setEmpName(String name) and getEmpName()). Hence the code can be maintained at any point of time without breaking the classes that uses the code. This improves the re-usability of the underlying class.