SlideShare ist ein Scribd-Unternehmen logo
1 von 24
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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Method overloading
Method overloadingMethod overloading
Method overloading
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Interface in java
Interface in javaInterface in java
Interface 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
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Data types in java
Data types in javaData types in java
Data types in java
 

Andere mochten auch

Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Conceptsthinkphp
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programmingSachin Sharma
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsRaja Sekhar
 
Practical OOP In Java
Practical OOP In JavaPractical OOP In Java
Practical OOP In Javawiradikusuma
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingMoutaz Haddara
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
Object oriented programming (oop) cs304 power point slides lecture 01
Object oriented programming (oop)   cs304 power point slides lecture 01Object oriented programming (oop)   cs304 power point slides lecture 01
Object oriented programming (oop) cs304 power point slides lecture 01Adil Kakakhel
 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Languagejaimefrozr
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingHüseyin Ergin
 
Java buzzwords
Java buzzwordsJava buzzwords
Java buzzwordsramesh517
 

Andere mochten auch (20)

Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Java Basic Oops Concept
Java Basic Oops ConceptJava Basic Oops Concept
Java Basic Oops Concept
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
 
Oop java
Oop javaOop java
Oop java
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwords
 
Practical OOP In Java
Practical OOP In JavaPractical OOP In Java
Practical OOP In Java
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Java Object Oriented Programming
Java Object Oriented Programming Java Object Oriented Programming
Java Object Oriented Programming
 
Object oriented programming (oop) cs304 power point slides lecture 01
Object oriented programming (oop)   cs304 power point slides lecture 01Object oriented programming (oop)   cs304 power point slides lecture 01
Object oriented programming (oop) cs304 power point slides lecture 01
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Java buzzwords
Java buzzwordsJava buzzwords
Java buzzwords
 
OOPs in Java
OOPs in JavaOOPs in Java
OOPs in Java
 

Ähnlich wie Java OOP Concepts Explained

Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshowilias ahmed
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
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...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Ayes Chinmay
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentSuresh Mohta
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)Khaled Anaqwa
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2Sherihan Anver
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satyaSatya Johnny
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEVinishA23
 
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Soumen Santra
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAVINASH KUMAR
 
Introduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxIntroduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxPoonam60376
 
Java programming basics
Java programming basicsJava programming basics
Java programming basicsHamid Ghorbani
 

Ähnlich wie Java OOP Concepts Explained (20)

Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2
 
Core java
Core javaCore java
Core java
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
 
Adv kvr -satya
Adv  kvr -satyaAdv  kvr -satya
Adv kvr -satya
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
 
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sir
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Java notes
Java notesJava notes
Java notes
 
Java mcq
Java mcqJava mcq
Java mcq
 
Introduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxIntroduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptx
 
1_JavIntro
1_JavIntro1_JavIntro
1_JavIntro
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 

Kürzlich hochgeladen

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 

Kürzlich hochgeladen (20)

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 

Java OOP Concepts Explained

  • 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: support@cpd-india.com www.cpd-india.com www.facebook.com/cpdtechnology