SlideShare a Scribd company logo
Main Concepts of OOP
• Encapsulation
• Inheritance
• Polymorphism
• Abstraction
Encapsulation
• Encapsulation is the technique of making the fields in a
class private and providing access to the fields via
public methods.
• The main benefit of encapsulation is the ability to
modify our implemented code without breaking the
code of others who use our code.
• Encapsulation gives maintainability, flexibility and
extensibility to our code.
Access Specifiers in java
• public
• private
• protected
• Default
Public access specifier
• A class, method, constructor, interface etc., declared
public can be accessed from any other class.
• Therefore fields, methods, blocks declared inside a
public class can be accessed from any class belonging
to the Java Universe.
• If the public class we are trying to access is in a
different package, then the public class still need to be
imported.
Private access specifiers
• Methods, Variables and Constructors that are declared private
can only be accessed within the declared class itself.
• Private access modifier is the most restrictive access level.
Class and interfaces cannot be private.
• Variables that are declared private can be accessed outside
the class if public getter methods are present in the class.
• Using the private modifier is the main way that an object
encapsulates itself and hide data from the outside world.
Sample code for private access
specifier
Protected access specifier
• Variables, methods and constructors which are declared
protected in a superclass can be accessed only by the
subclasses in other package or any class within the
package of the protected members' class.
• The protected access modifier cannot be applied to
class and interfaces. Methods, fields can be declared
protected, however methods and fields in a interface
cannot be declared protected.
Sample code for protected access
specifier
Default specifier
• The default specifier is used to make a class visible to
all the other classes in its package but not visible to
classes from other packages
Inheritance
• Inheritance is a compile-time mechanism in Java that
allows you to extend a class with another class
• The keyword extends is used for inheriting a Class.
• The class which extends some other class is called as
derived class
• The base class is called as the super class or parent
class.
Types of inheritance
• Simple inheritance
• Multilevel inheritance
• Hierarchical inheritance
• Hybrid inheritance
Simple inheritance
• There are only 1 base class and 1 derived class
• Syntax:
Class Parentclass
{
}
Class Dclass extendsParentclass
{
}
Simple inheritance sample code and
output
Multilevel inheritance
• It contains derived classes which are in turn base class to another class.
class Base
{
}
class Derived1 extends Base
{
}
class Derived2 extends Derived1
{
}
Multilevel inheritance sample code
and output
Hierarchical inheritance
• It contains one base class and more than one derived class.
class Base
{
}
class Derived1 extends Base
{
}
class Derived2 extends Base{ }
Sample code and output for
Hierarchical inheritance
Hybrid inheritance
• It is a combination of any two or more inheritances.
Sample code for hybrid inheritance
Interface
• An interface in Java is similar to a class, but the body of
an interface can include only abstract methods and final
fields (constants).
• A class implements an interface by providing code for
each method declared by the interface.
• The keyword used in interface concepts are interface
and implements
Syntax for interface
interface interfacename
{
method_declaration();
}
class A implements interfacename
{
method_declaration(){ }
}
Interface sample code
Interface sample output
Any queries??
Thank you

More Related Content

PPT
Access Protection
myrajendra
 
PDF
Access modifiers in java
Muthukumaran Subramanian
 
PPTX
10 access control
dhrubo kayal
 
PPTX
Access modifiers in java
Sourabrata Mukherjee
 
PPTX
OOPS – General Understanding in .NET
Sabith Byari
 
PDF
Java programming -Object-Oriented Thinking- Inheritance
Jyothishmathi Institute of Technology and Science Karimnagar
 
PPTX
Visibility control in java
Tech_MX
 
PDF
Non access modifiers
Muthukumaran Subramanian
 
Access Protection
myrajendra
 
Access modifiers in java
Muthukumaran Subramanian
 
10 access control
dhrubo kayal
 
Access modifiers in java
Sourabrata Mukherjee
 
OOPS – General Understanding in .NET
Sabith Byari
 
Java programming -Object-Oriented Thinking- Inheritance
Jyothishmathi Institute of Technology and Science Karimnagar
 
Visibility control in java
Tech_MX
 
Non access modifiers
Muthukumaran Subramanian
 

What's hot (20)

PPTX
Chap1 packages
raksharao
 
PPTX
Polymorphism
Nuha Noor
 
PPS
Dacj 2-1 a
Niit Care
 
PDF
JAVA PROGRAMMING – Packages - Stream based I/O
Jyothishmathi Institute of Technology and Science Karimnagar
 
PPTX
Packages
Nuha Noor
 
PPT
inheritance
Mohit Patodia
 
PPT
Inheritance and Polymorphism
BG Java EE Course
 
PPTX
INHERITANCE-Oopc ppt-ta4
Ashutosh Makwana
 
PPTX
Object oriented programming 3 object oriented concepts
Vaibhav Khanna
 
PPT
Interfaces
myrajendra
 
PPTX
Inheritance in oops
Hirra Sultan
 
PPTX
Inheritance in Java
Ferdin Joe John Joseph PhD
 
DOC
Questpond - Top 10 Interview Questions and Answers on OOPS
gdrealspace
 
PDF
java-06inheritance
Arjun Shanka
 
PPTX
27csharp
Sireesh K
 
PPT
Inheritance, Object Oriented Programming
Arslan Waseem
 
PPTX
Packages and Interfaces
AkashDas112
 
PPTX
Basics of java (1)
raj upadhyay
 
Chap1 packages
raksharao
 
Polymorphism
Nuha Noor
 
Dacj 2-1 a
Niit Care
 
JAVA PROGRAMMING – Packages - Stream based I/O
Jyothishmathi Institute of Technology and Science Karimnagar
 
Packages
Nuha Noor
 
inheritance
Mohit Patodia
 
Inheritance and Polymorphism
BG Java EE Course
 
INHERITANCE-Oopc ppt-ta4
Ashutosh Makwana
 
Object oriented programming 3 object oriented concepts
Vaibhav Khanna
 
Interfaces
myrajendra
 
Inheritance in oops
Hirra Sultan
 
Inheritance in Java
Ferdin Joe John Joseph PhD
 
Questpond - Top 10 Interview Questions and Answers on OOPS
gdrealspace
 
java-06inheritance
Arjun Shanka
 
27csharp
Sireesh K
 
Inheritance, Object Oriented Programming
Arslan Waseem
 
Packages and Interfaces
AkashDas112
 
Basics of java (1)
raj upadhyay
 
Ad

Viewers also liked (12)

PPTX
Object Oriented Programming Concepts
Mohamed Emam
 
PDF
Java Programming - 05 access control in java
Danairat Thanabodithammachari
 
PPSX
String and string manipulation x
Shahjahan Samoon
 
PPT
Lecture09
elearning_portal
 
PPSX
Concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
PPTX
Interesting Concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
PDF
Java packages and access specifiers
ashishspace
 
PPTX
[OOP - Lec 07] Access Specifiers
Muhammad Hammad Waseem
 
PPTX
Encapsulation
Githushan Gengaparam
 
PPT
Object Oriented Programming with Java
backdoor
 
PPTX
oops concept in java | object oriented programming in java
CPD INDIA
 
PPTX
encapsulation, inheritance, overriding, overloading
Shivam Singhal
 
Object Oriented Programming Concepts
Mohamed Emam
 
Java Programming - 05 access control in java
Danairat Thanabodithammachari
 
String and string manipulation x
Shahjahan Samoon
 
Lecture09
elearning_portal
 
Concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
Interesting Concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
Java packages and access specifiers
ashishspace
 
[OOP - Lec 07] Access Specifiers
Muhammad Hammad Waseem
 
Encapsulation
Githushan Gengaparam
 
Object Oriented Programming with Java
backdoor
 
oops concept in java | object oriented programming in java
CPD INDIA
 
encapsulation, inheritance, overriding, overloading
Shivam Singhal
 
Ad

Similar to Oops (inheritance&interface) (20)

PDF
Java introduction
Muthukumaran Subramanian
 
PDF
Chapter 03 enscapsulation
Nurhanna Aziz
 
PPTX
Unit II Inheritance ,Interface and Packages.pptx
pranalisonawane8600
 
PPTX
27c
Sireesh K
 
PPTX
object oriented programming unit two ppt
isiagnel2
 
PPTX
OOPS (Object Oriented Programming System) CONCEPTS
HariShiva7
 
PPTX
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
saurabhthege
 
PPTX
Access modifier and inheritance
Dikshyanta Dhungana
 
PPTX
Java Access Specifier
DeeptiJava
 
PPTX
) Function overriding, Member Classes Nesting of Classes.pptx
sachinkumar541404
 
PPT
L7 inheritance
teach4uin
 
PPT
L7 inheritance
teach4uin
 
PPT
Java OOP s concepts and buzzwords
Raja Sekhar
 
PPTX
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G
 
PPTX
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
PPTX
Presentation2.ppt java basic core ppt .
KeshavMotivation
 
PPTX
chapter 5 concepts of object oriented programming
WondimuBantihun1
 
PPTX
Access Modifiers of oop classes concept.pptx
umarshafi527
 
PPTX
Std 12 computer chapter 8 classes and object in java (part 2)
Nuzhat Memon
 
PPTX
arthimetic operator,classes,objects,instant
ssuser77162c
 
Java introduction
Muthukumaran Subramanian
 
Chapter 03 enscapsulation
Nurhanna Aziz
 
Unit II Inheritance ,Interface and Packages.pptx
pranalisonawane8600
 
object oriented programming unit two ppt
isiagnel2
 
OOPS (Object Oriented Programming System) CONCEPTS
HariShiva7
 
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
saurabhthege
 
Access modifier and inheritance
Dikshyanta Dhungana
 
Java Access Specifier
DeeptiJava
 
) Function overriding, Member Classes Nesting of Classes.pptx
sachinkumar541404
 
L7 inheritance
teach4uin
 
L7 inheritance
teach4uin
 
Java OOP s concepts and buzzwords
Raja Sekhar
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G
 
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
Presentation2.ppt java basic core ppt .
KeshavMotivation
 
chapter 5 concepts of object oriented programming
WondimuBantihun1
 
Access Modifiers of oop classes concept.pptx
umarshafi527
 
Std 12 computer chapter 8 classes and object in java (part 2)
Nuzhat Memon
 
arthimetic operator,classes,objects,instant
ssuser77162c
 

More from Muthukumaran Subramanian (17)

PPTX
Struts introduction
Muthukumaran Subramanian
 
PDF
Operators in java
Muthukumaran Subramanian
 
PDF
Threads concept in java
Muthukumaran Subramanian
 
PDF
StringTokenizer in java
Muthukumaran Subramanian
 
PDF
Overriding methods
Muthukumaran Subramanian
 
PDF
Jdbc connectivity in java
Muthukumaran Subramanian
 
PDF
Garbage collection in java
Muthukumaran Subramanian
 
PDF
Files in java
Muthukumaran Subramanian
 
PDF
Exception handling
Muthukumaran Subramanian
 
PDF
Currency class
Muthukumaran Subramanian
 
PDF
Timer class in java
Muthukumaran Subramanian
 
PDF
Calendar class in java
Muthukumaran Subramanian
 
PDF
Classes and objects in java
Muthukumaran Subramanian
 
PDF
intorduction to Arrays in java
Muthukumaran Subramanian
 
PDF
Abstract classes
Muthukumaran Subramanian
 
PDF
Collections and generics
Muthukumaran Subramanian
 
Struts introduction
Muthukumaran Subramanian
 
Operators in java
Muthukumaran Subramanian
 
Threads concept in java
Muthukumaran Subramanian
 
StringTokenizer in java
Muthukumaran Subramanian
 
Overriding methods
Muthukumaran Subramanian
 
Jdbc connectivity in java
Muthukumaran Subramanian
 
Garbage collection in java
Muthukumaran Subramanian
 
Exception handling
Muthukumaran Subramanian
 
Currency class
Muthukumaran Subramanian
 
Timer class in java
Muthukumaran Subramanian
 
Calendar class in java
Muthukumaran Subramanian
 
Classes and objects in java
Muthukumaran Subramanian
 
intorduction to Arrays in java
Muthukumaran Subramanian
 
Abstract classes
Muthukumaran Subramanian
 
Collections and generics
Muthukumaran Subramanian
 

Recently uploaded (20)

PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
Software Development Methodologies in 2025
KodekX
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
This slide provides an overview Technology
mineshkharadi333
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 

Oops (inheritance&interface)

  • 1. Main Concepts of OOP • Encapsulation • Inheritance • Polymorphism • Abstraction
  • 2. Encapsulation • Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. • The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. • Encapsulation gives maintainability, flexibility and extensibility to our code.
  • 3. Access Specifiers in java • public • private • protected • Default
  • 4. Public access specifier • A class, method, constructor, interface etc., declared public can be accessed from any other class. • Therefore fields, methods, blocks declared inside a public class can be accessed from any class belonging to the Java Universe. • If the public class we are trying to access is in a different package, then the public class still need to be imported.
  • 5. Private access specifiers • Methods, Variables and Constructors that are declared private can only be accessed within the declared class itself. • Private access modifier is the most restrictive access level. Class and interfaces cannot be private. • Variables that are declared private can be accessed outside the class if public getter methods are present in the class. • Using the private modifier is the main way that an object encapsulates itself and hide data from the outside world.
  • 6. Sample code for private access specifier
  • 7. Protected access specifier • Variables, methods and constructors which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members' class. • The protected access modifier cannot be applied to class and interfaces. Methods, fields can be declared protected, however methods and fields in a interface cannot be declared protected.
  • 8. Sample code for protected access specifier
  • 9. Default specifier • The default specifier is used to make a class visible to all the other classes in its package but not visible to classes from other packages
  • 10. Inheritance • Inheritance is a compile-time mechanism in Java that allows you to extend a class with another class • The keyword extends is used for inheriting a Class. • The class which extends some other class is called as derived class • The base class is called as the super class or parent class.
  • 11. Types of inheritance • Simple inheritance • Multilevel inheritance • Hierarchical inheritance • Hybrid inheritance
  • 12. Simple inheritance • There are only 1 base class and 1 derived class • Syntax: Class Parentclass { } Class Dclass extendsParentclass { }
  • 13. Simple inheritance sample code and output
  • 14. Multilevel inheritance • It contains derived classes which are in turn base class to another class. class Base { } class Derived1 extends Base { } class Derived2 extends Derived1 { }
  • 15. Multilevel inheritance sample code and output
  • 16. Hierarchical inheritance • It contains one base class and more than one derived class. class Base { } class Derived1 extends Base { } class Derived2 extends Base{ }
  • 17. Sample code and output for Hierarchical inheritance
  • 18. Hybrid inheritance • It is a combination of any two or more inheritances.
  • 19. Sample code for hybrid inheritance
  • 20. Interface • An interface in Java is similar to a class, but the body of an interface can include only abstract methods and final fields (constants). • A class implements an interface by providing code for each method declared by the interface. • The keyword used in interface concepts are interface and implements
  • 21. Syntax for interface interface interfacename { method_declaration(); } class A implements interfacename { method_declaration(){ } }