SlideShare a Scribd company logo
3
Most read
11
Most read
13
Most read
Object-Oriented
Programming Concept in Java
Call Us: 01165164822
CPD TECHNOLOGIESTM
An ISO 9001: 2008 Certified
Add:- Block C 9/8, Sector -7, Rohini, Delhi-110085, India
www.cpd-india.com Blog.cpd-india.com
If you've never used an object-oriented programming
language before, you'll need to learn a few basic concepts
before you can begin writing any code. This lesson will
introduce you to objects, classes, inheritance, interfaces, and
packages. Each discussion focuses on how these concepts
relate to the real world.
Object Oriented Programming
What Is a Class?
A class is a blueprint (It is user defined data types it could be anything) or
prototype from which objects are created. This section defines a class that
models the state and behavior of a real-world object. It intentionally
focuses on the basics, showing how even simple classes can cleanly model
state and behavior.
E.g.
class Demo {
public static void main (String args[]) {
System.out.println("Welcome to Java”);
}
}
What Is an Object?
An object is a software bundle of related state and behavior.
Software objects are often used to model the real-world
objects that you find in everyday life (Object is real world
Entity to represent a physical instance of a Class). A software
object maintains its state in variables and implements its
behavior with methods.
E.g.
What Is a Package?
A Java package is a mechanism for organizing Java classes into
namespaces similar to the modules of Modula. Java packages
can be stored in compressed files called JAR files, allowing
classes to download faster as a group rather than one at a time.
Programmers also typically use packages to organize classes
belonging to the same category or providing similar
functionality.
•A package provides a unique namespace for the types it
contains.
•Classes in the same package can access each other's
package-access members.
E.g:-
import java.lang.*;
import java.util.*;
import java.io.*;
import java.awt.*;
What Is Inheritance?
Inheritance provides a powerful and natural mechanism for
organizing and structuring your software. Now we will
explain how classes inherit state and behavior from their
super classes, and explains how to derive one class from
another using the simple syntax provided by the Java
programming language.
E.g. Single Inheritance
class A
{
//statements;
}
class B extends A
{
public static void main (String ar[])
{
System.out.println ("Welcome to Java Programming");
}
}
E.g. : Multilevel Inheritance
class A
{
//statements;
}
class B extends A
{
//statements;
}
class C extends B
{
//statements;
public static void main(String ar[])
{
//statements
}
}
E.g. Hierarchal Inheritance
class A
{
//statements;
}
class B extends A
{
//statements;
}
class C extends A
{
public static void main(String ar[])
{
//statements;
}
}
What is an Abstraction?
Abstraction is the process of abstraction in Java is used to hide
certain details and only show the essential features of the object.
In other words, it deals with the outside view of an object
(interface).
Abstract class cannot be instantiated; the class does not have
much use unless it is subclass. This is typically how abstract
classes come about during the design phase. A parent class
contains the common functionality of a collection of child
classes, but the parent class itself is too abstract to be used on
its own.
E.g.
abstract class A
{
public abstract void sum(int x, int y);
}
class B extends A
{
public void sum(int x,int y)
{
System.out.println(x+y);
}
public static void main(String ar[])
{
B obj=new B();
obj.sum(2,5);
}
}
What Is an Interface?
An interface is a collection of abstract methods (it means all
methods are only declared in an Interface). A class implements an
interface, thereby inheriting the abstract methods of the interface.
And that class implements interface then you need to defined all
abstract function which is present in an Interface.
An interface is not a class. Writing an interface is similar to writing
a class, but they are two different concepts. A class describes the
attributes and behaviors of an object. An interface contains
behaviors that a class implements.
E.g.
interface A
{
public void sumData(int x, int y);
}
class Demo implements A
{
public void sumData (int x, int y)
{
System.out.println ("Total is "+(x+y));
}
public static void main (String ar[])
{
Demo d=new Demo ();
d.sumData (10, 20);
}
}
What Is An Encapsulation?
Encapsulation is one of the four fundamental OOP concepts.
The other three are inheritance, polymorphism, and
abstraction.
Encapsulation is the technique of making the fields in a class
private and providing access to the fields via public methods.
If a field is declared private, it cannot be accessed by anyone
outside the class, thereby hiding the fields within the class.
For this reason, encapsulation is also referred to as data
hiding.
E.g.
public class EncapTest
{
private String name;
private String idNum;
private int age;
public int getAge()
{
return age;
}
public String getName()
{
return name;
}
public String getIdNum()
{
return idNum;
}
public void setAge( int newAge)
{
age = newAge;
}
public void setName(String newName)
{
name = newName;
}
public void setIdNum( String newId)
{
idNum = newId;
}
}
public class RunEncap
{
public static void main(String args[])
{
EncapTest encap = new EncapTest();
encap.setName("James");
encap.setAge(20);
encap.setIdNum("12343ms");
System.out.print("Name : " + encap.getName()+" Age
:"+encap.getAge());
}
}
What is Polymorphism?
Method overloading and method overriding uses concept of
Polymorphism in Java where method name remains same in
two classes but actual method called by JVM depends upon
object at run time and done by dynamic binding in Java. Java
supports both overloading and overriding of methods. In case
of overloading method signature changes while in case of
overriding method signature remains same and binding and
invocation of method is decided on runtime based on actual
object.
Method overloading
In Method overloading we have two or more functions with
the same name but different arguments. Arguments must
be changed on the bases of Number, orders and Data types.
E.g.
class A
{
public void f1(int x)
{
System.out.println(x*x);
}
public void f1(int x,int y)
{
System.out.println(x*y);
}
public static void main(String ar[])
{
A a=new A();
a.f1(5);
a.f1(2,3);
}
}
Method Overriding
We have two classes and both classes have a function with the
same name and same Parameters inheritance is necessary.
Eg.
class B
{
public void f1(int x,int y)
{
System.out.println(x+y);
}
}
class A extends B
{
public void f1(int x,int y)
{
System.out.println(x*y);
}
public static void main(String ar[])
{
A a=new A();
a.f1(5,5);
B b=new B();
b.f1(2,3);
}
}
CPD TECHNOLOGIES
Block C 9/8, Sector -7, Rohini, Delhi-110085, India
Landmark: Near Rohini East Metro Station,
Opposite Metro Pillar No-397
Telephone: 011-65164822
Mobile: +91- 8860352748
Email: support@cpd-india.com
www.cpd-india.com
www.facebook.com/cpdtechnology

More Related Content

What's hot (20)

PDF
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PDF
Introduction to oops concepts
Nilesh Dalvi
 
PPSX
JDBC: java DataBase connectivity
Tanmoy Barman
 
PPT
Object Oriented Programming Concepts
thinkphp
 
PPTX
Inheritance in java
RahulAnanda1
 
PPTX
Java swing
Apurbo Datta
 
PPTX
Arrays in Java
Abhilash Nair
 
PPTX
Method overloading
Lovely Professional University
 
PPT
Java collections concept
kumar gaurav
 
PPTX
MULTI THREADING IN JAVA
VINOTH R
 
PPTX
Inheritance in java
Tech_MX
 
PPTX
Arrays in java
Arzath Areeff
 
PPTX
Java exception handling
BHUVIJAYAVELU
 
PPS
Introduction to class in java
kamal kotecha
 
PPTX
classes and objects in C++
HalaiHansaika
 
PPT
Java Collections Framework
Sony India Software Center
 
PPT
Oops in Java
malathip12
 
PDF
Java threads
Prabhakaran V M
 
PPT
Java buzzwords
ramesh517
 
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
Classes, objects in JAVA
Abhilash Nair
 
Introduction to oops concepts
Nilesh Dalvi
 
JDBC: java DataBase connectivity
Tanmoy Barman
 
Object Oriented Programming Concepts
thinkphp
 
Inheritance in java
RahulAnanda1
 
Java swing
Apurbo Datta
 
Arrays in Java
Abhilash Nair
 
Method overloading
Lovely Professional University
 
Java collections concept
kumar gaurav
 
MULTI THREADING IN JAVA
VINOTH R
 
Inheritance in java
Tech_MX
 
Arrays in java
Arzath Areeff
 
Java exception handling
BHUVIJAYAVELU
 
Introduction to class in java
kamal kotecha
 
classes and objects in C++
HalaiHansaika
 
Java Collections Framework
Sony India Software Center
 
Oops in Java
malathip12
 
Java threads
Prabhakaran V M
 
Java buzzwords
ramesh517
 

Viewers also liked (19)

PPT
Object Oriented Programming with Java
backdoor
 
PPT
Object-oriented concepts
BG Java EE Course
 
PPT
Basic concepts of object oriented programming
Sachin Sharma
 
PPT
Oop java
Minal Maniar
 
PPT
Oops ppt
abhayjuneja
 
PPT
Java OOP s concepts and buzzwords
Raja Sekhar
 
KEY
Practical OOP In Java
wiradikusuma
 
PPTX
Introduction to Object Oriented Programming
Moutaz Haddara
 
PPT
Java tutorial PPT
Intelligo Technologies
 
PPT
Object Oriented Programming with Java
Jussi Pohjolainen
 
PPSX
Java Object Oriented Programming
University of Potsdam
 
PPT
Object oriented programming (oop) cs304 power point slides lecture 01
Adil Kakakhel
 
PPT
Core java concepts
Ram132
 
PDF
Introduction to Java Programming Language
jaimefrozr
 
PPT
Java Tutorial
Vijay A Raj
 
PDF
Object oriented programming
Hüseyin Ergin
 
PPTX
OOPs in Java
Ranjith Sekar
 
PDF
It Is Possible to Do Object-Oriented Programming in Java
Kevlin Henney
 
PDF
JAVA Object Oriented Programming (OOP)
Prof. Erwin Globio
 
Object Oriented Programming with Java
backdoor
 
Object-oriented concepts
BG Java EE Course
 
Basic concepts of object oriented programming
Sachin Sharma
 
Oop java
Minal Maniar
 
Oops ppt
abhayjuneja
 
Java OOP s concepts and buzzwords
Raja Sekhar
 
Practical OOP In Java
wiradikusuma
 
Introduction to Object Oriented Programming
Moutaz Haddara
 
Java tutorial PPT
Intelligo Technologies
 
Object Oriented Programming with Java
Jussi Pohjolainen
 
Java Object Oriented Programming
University of Potsdam
 
Object oriented programming (oop) cs304 power point slides lecture 01
Adil Kakakhel
 
Core java concepts
Ram132
 
Introduction to Java Programming Language
jaimefrozr
 
Java Tutorial
Vijay A Raj
 
Object oriented programming
Hüseyin Ergin
 
OOPs in Java
Ranjith Sekar
 
It Is Possible to Do Object-Oriented Programming in Java
Kevlin Henney
 
JAVA Object Oriented Programming (OOP)
Prof. Erwin Globio
 
Ad

Similar to oops concept in java | object oriented programming in java (20)

PDF
Core Java Interview Questions PDF By ScholarHat
Scholarhat
 
PDF
Java Interview Questions PDF By ScholarHat
Scholarhat
 
PPSX
Oop features java presentationshow
ilias ahmed
 
PPTX
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Sagar Verma
 
PPTX
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Ayes Chinmay
 
PPTX
Basic concept of class, method , command line-argument
Suresh Mohta
 
PPTX
Android Training (Java Review)
Khaled Anaqwa
 
PPTX
Java interview questions 2
Sherihan Anver
 
PPTX
Core java
Ganesh Chittalwar
 
PPT
web program-Inheritance,pack&except in Java.ppt
mcjaya2024
 
PDF
Advance java kvr -satya
Satya Johnny
 
PDF
Adv kvr -satya
Jyothsna Sree
 
PPTX
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
VinishA23
 
PPTX
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Soumen Santra
 
PDF
Advanced java jee material by KV Rao sir
AVINASH KUMAR
 
PPTX
Abstraction encapsulation inheritance polymorphism
PriyadharshiniG41
 
PPTX
Unit3 part1-class
DevaKumari Vijay
 
PPTX
Inheritance & interface ppt Inheritance
narikamalliy
 
PPTX
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
PPTX
Objects and classes in OO Programming concepts
researchveltech
 
Core Java Interview Questions PDF By ScholarHat
Scholarhat
 
Java Interview Questions PDF By ScholarHat
Scholarhat
 
Oop features java presentationshow
ilias ahmed
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Sagar Verma
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Ayes Chinmay
 
Basic concept of class, method , command line-argument
Suresh Mohta
 
Android Training (Java Review)
Khaled Anaqwa
 
Java interview questions 2
Sherihan Anver
 
web program-Inheritance,pack&except in Java.ppt
mcjaya2024
 
Advance java kvr -satya
Satya Johnny
 
Adv kvr -satya
Jyothsna Sree
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
VinishA23
 
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Soumen Santra
 
Advanced java jee material by KV Rao sir
AVINASH KUMAR
 
Abstraction encapsulation inheritance polymorphism
PriyadharshiniG41
 
Unit3 part1-class
DevaKumari Vijay
 
Inheritance & interface ppt Inheritance
narikamalliy
 
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
Objects and classes in OO Programming concepts
researchveltech
 
Ad

Recently uploaded (20)

PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 

oops concept in java | object oriented programming in java

  • 1. Object-Oriented Programming Concept in Java Call Us: 01165164822 CPD TECHNOLOGIESTM An ISO 9001: 2008 Certified Add:- Block C 9/8, Sector -7, Rohini, Delhi-110085, India www.cpd-india.com Blog.cpd-india.com
  • 2. If you've never used an object-oriented programming language before, you'll need to learn a few basic concepts before you can begin writing any code. This lesson will introduce you to objects, classes, inheritance, interfaces, and packages. Each discussion focuses on how these concepts relate to the real world. Object Oriented Programming
  • 3. What Is a Class? A class is a blueprint (It is user defined data types it could be anything) or prototype from which objects are created. This section defines a class that models the state and behavior of a real-world object. It intentionally focuses on the basics, showing how even simple classes can cleanly model state and behavior. E.g. class Demo { public static void main (String args[]) { System.out.println("Welcome to Java”); } }
  • 4. What Is an Object? An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life (Object is real world Entity to represent a physical instance of a Class). A software object maintains its state in variables and implements its behavior with methods. E.g.
  • 5. What Is a Package? A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time. Programmers also typically use packages to organize classes belonging to the same category or providing similar functionality.
  • 6. •A package provides a unique namespace for the types it contains. •Classes in the same package can access each other's package-access members. E.g:- import java.lang.*; import java.util.*; import java.io.*; import java.awt.*;
  • 7. What Is Inheritance? Inheritance provides a powerful and natural mechanism for organizing and structuring your software. Now we will explain how classes inherit state and behavior from their super classes, and explains how to derive one class from another using the simple syntax provided by the Java programming language.
  • 8. E.g. Single Inheritance class A { //statements; } class B extends A { public static void main (String ar[]) { System.out.println ("Welcome to Java Programming"); } }
  • 9. E.g. : Multilevel Inheritance class A { //statements; } class B extends A { //statements; } class C extends B { //statements; public static void main(String ar[]) { //statements } }
  • 10. E.g. Hierarchal Inheritance class A { //statements; } class B extends A { //statements; } class C extends A { public static void main(String ar[]) { //statements; } }
  • 11. What is an Abstraction? Abstraction is the process of abstraction in Java is used to hide certain details and only show the essential features of the object. In other words, it deals with the outside view of an object (interface). Abstract class cannot be instantiated; the class does not have much use unless it is subclass. This is typically how abstract classes come about during the design phase. A parent class contains the common functionality of a collection of child classes, but the parent class itself is too abstract to be used on its own.
  • 12. E.g. abstract class A { public abstract void sum(int x, int y); } class B extends A { public void sum(int x,int y) { System.out.println(x+y); } public static void main(String ar[]) { B obj=new B(); obj.sum(2,5); } }
  • 13. What Is an Interface? An interface is a collection of abstract methods (it means all methods are only declared in an Interface). A class implements an interface, thereby inheriting the abstract methods of the interface. And that class implements interface then you need to defined all abstract function which is present in an Interface. An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements.
  • 14. E.g. interface A { public void sumData(int x, int y); } class Demo implements A { public void sumData (int x, int y) { System.out.println ("Total is "+(x+y)); } public static void main (String ar[]) { Demo d=new Demo (); d.sumData (10, 20); } }
  • 15. What Is An Encapsulation? Encapsulation is one of the four fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction. Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding.
  • 16. E.g. public class EncapTest { private String name; private String idNum; private int age; public int getAge() { return age; } public String getName() { return name; } public String getIdNum() { return idNum; }
  • 17. public void setAge( int newAge) { age = newAge; } public void setName(String newName) { name = newName; } public void setIdNum( String newId) { idNum = newId; } }
  • 18. public class RunEncap { public static void main(String args[]) { EncapTest encap = new EncapTest(); encap.setName("James"); encap.setAge(20); encap.setIdNum("12343ms"); System.out.print("Name : " + encap.getName()+" Age :"+encap.getAge()); } }
  • 19. What is Polymorphism? Method overloading and method overriding uses concept of Polymorphism in Java where method name remains same in two classes but actual method called by JVM depends upon object at run time and done by dynamic binding in Java. Java supports both overloading and overriding of methods. In case of overloading method signature changes while in case of overriding method signature remains same and binding and invocation of method is decided on runtime based on actual object.
  • 20. Method overloading In Method overloading we have two or more functions with the same name but different arguments. Arguments must be changed on the bases of Number, orders and Data types. E.g. class A { public void f1(int x) { System.out.println(x*x); } public void f1(int x,int y) { System.out.println(x*y); }
  • 21. public static void main(String ar[]) { A a=new A(); a.f1(5); a.f1(2,3); } }
  • 22. Method Overriding We have two classes and both classes have a function with the same name and same Parameters inheritance is necessary. Eg. class B { public void f1(int x,int y) { System.out.println(x+y); } }
  • 23. class A extends B { public void f1(int x,int y) { System.out.println(x*y); } public static void main(String ar[]) { A a=new A(); a.f1(5,5); B b=new B(); b.f1(2,3); } }
  • 24. CPD TECHNOLOGIES Block C 9/8, Sector -7, Rohini, Delhi-110085, India Landmark: Near Rohini East Metro Station, Opposite Metro Pillar No-397 Telephone: 011-65164822 Mobile: +91- 8860352748 Email: [email protected] www.cpd-india.com www.facebook.com/cpdtechnology