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
PDF
Access modifiers in java
PPTX
10 access control
PPTX
Access modifiers in java
PPTX
OOPS – General Understanding in .NET
PDF
Java programming -Object-Oriented Thinking- Inheritance
PPTX
Visibility control in java
PDF
Non access modifiers
Access Protection
Access modifiers in java
10 access control
Access modifiers in java
OOPS – General Understanding in .NET
Java programming -Object-Oriented Thinking- Inheritance
Visibility control in java
Non access modifiers

What's hot (20)

PPTX
Chap1 packages
PPTX
Polymorphism
PPS
Dacj 2-1 a
PDF
JAVA PROGRAMMING – Packages - Stream based I/O
PPTX
Packages
PPT
inheritance
PPT
Inheritance and Polymorphism
PPTX
INHERITANCE-Oopc ppt-ta4
PPTX
Object oriented programming 3 object oriented concepts
PPT
Interfaces
PPTX
Inheritance in oops
PPTX
Inheritance in Java
DOC
Questpond - Top 10 Interview Questions and Answers on OOPS
PDF
java-06inheritance
PPTX
27csharp
PPT
Inheritance, Object Oriented Programming
PPTX
Packages and Interfaces
PPTX
Basics of java (1)
Chap1 packages
Polymorphism
Dacj 2-1 a
JAVA PROGRAMMING – Packages - Stream based I/O
Packages
inheritance
Inheritance and Polymorphism
INHERITANCE-Oopc ppt-ta4
Object oriented programming 3 object oriented concepts
Interfaces
Inheritance in oops
Inheritance in Java
Questpond - Top 10 Interview Questions and Answers on OOPS
java-06inheritance
27csharp
Inheritance, Object Oriented Programming
Packages and Interfaces
Basics of java (1)
Ad

Viewers also liked (12)

PPTX
Object Oriented Programming Concepts
PDF
Java Programming - 05 access control in java
PPSX
String and string manipulation x
PPT
Lecture09
PPSX
Concept of Object Oriented Programming
PPTX
Interesting Concept of Object Oriented Programming
PDF
Java packages and access specifiers
PPTX
[OOP - Lec 07] Access Specifiers
PPTX
Encapsulation
PPT
Object Oriented Programming with Java
PPTX
oops concept in java | object oriented programming in java
PPTX
encapsulation, inheritance, overriding, overloading
Object Oriented Programming Concepts
Java Programming - 05 access control in java
String and string manipulation x
Lecture09
Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming
Java packages and access specifiers
[OOP - Lec 07] Access Specifiers
Encapsulation
Object Oriented Programming with Java
oops concept in java | object oriented programming in java
encapsulation, inheritance, overriding, overloading
Ad

Similar to Oops (inheritance&interface) (20)

PDF
Java introduction
PDF
Chapter 03 enscapsulation
PPTX
OBJECT ORIENTED PROGRAMMING_Unit2_firsthalf Updated.pptx
PPTX
Unit II Inheritance ,Interface and Packages.pptx
PPTX
OBJECT ORIENTED PROGRAMMING_Unit2_NOTES.pptx
PPTX
PPTX
object oriented programming unit two ppt
PPTX
OOPS (Object Oriented Programming System) CONCEPTS
PPTX
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
PPTX
Access modifier and inheritance
PPTX
Java Access Specifier
PPTX
OBJECT ORIENTED PROGRAMMING Unit2 second half.pptx
PPTX
) Function overriding, Member Classes Nesting of Classes.pptx
PPT
L7 inheritance
PPT
L7 inheritance
PPT
Java OOP s concepts and buzzwords
PPTX
OCP Java (OCPJP) 8 Exam Quick Reference Card
PPTX
PPT Lecture-1.4.pptx
PPTX
Presentation2.ppt java basic core ppt .
PPTX
chapter 5 concepts of object oriented programming
Java introduction
Chapter 03 enscapsulation
OBJECT ORIENTED PROGRAMMING_Unit2_firsthalf Updated.pptx
Unit II Inheritance ,Interface and Packages.pptx
OBJECT ORIENTED PROGRAMMING_Unit2_NOTES.pptx
object oriented programming unit two ppt
OOPS (Object Oriented Programming System) CONCEPTS
Inheritance in java.pptx_20241025_101324_0000.pptx.pptx
Access modifier and inheritance
Java Access Specifier
OBJECT ORIENTED PROGRAMMING Unit2 second half.pptx
) Function overriding, Member Classes Nesting of Classes.pptx
L7 inheritance
L7 inheritance
Java OOP s concepts and buzzwords
OCP Java (OCPJP) 8 Exam Quick Reference Card
PPT Lecture-1.4.pptx
Presentation2.ppt java basic core ppt .
chapter 5 concepts of object oriented programming

More from Muthukumaran Subramanian (17)

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

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
cuic standard and advanced reporting.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Cloud computing and distributed systems.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
KodekX | Application Modernization Development
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Empathic Computing: Creating Shared Understanding
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
Teaching material agriculture food technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Programs and apps: productivity, graphics, security and other tools
Unlocking AI with Model Context Protocol (MCP)
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Dropbox Q2 2025 Financial Results & Investor Presentation
cuic standard and advanced reporting.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Cloud computing and distributed systems.
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
KodekX | Application Modernization Development
Chapter 3 Spatial Domain Image Processing.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Empathic Computing: Creating Shared Understanding
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Teaching material agriculture food technology
The AUB Centre for AI in Media Proposal.docx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

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(){ } }