This document discusses the key concepts of object-oriented programming (OOP) including objects, classes, encapsulation, inheritance, polymorphism, and abstraction. It defines objects as instances of classes that have data fields and methods. Classes contain both data and functions and can have private, public, or protected members. Encapsulation binds data and functions into a class. Inheritance allows deriving new classes from existing ones. Polymorphism enables classes to provide different implementations of methods with the same name. Abstraction simplifies complexity by modeling appropriate classes for a problem.
Disclaimer: This presentationis prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
Object oriented programming
•is a programming paradigm that represents
concepts as “objects” that have data fields
and associated procedures known as
methods.
• data fields :attributes that describe objects.
• methods : some procedures designed for a
specific task.
5.
Object
• which areusually instances of classes, are
used to interact with one another to design
applications and computer programs.
• An object is an instantiation of class. In terms
of variables, a class would be a type, and an
object would be a variable.
6.
Class
• A classis an expanded concept of a data
structure: instead of holding only data, it can
hold both data and functions.
e.g. class class_name{
access_specifier_1:
member_1;
access_specifier_2:
member_2;
………………..
}
7.
Members of Class
•Private: private members are accessible only
in the class itself.
• Public: public members are accessible outside
the class(anywhere).
• Protected :protected members are accessible
in the same package, and in the subclasses of
the class and inside the class.
Encapsulation
• It isthe mechanism that binds the data &
function in one form known as class. The data
and function may be private or public.
• Encapsulation guarantees the integrity of the
data contained in the object.
Inheritance
• Mechanism ofderiving a new class from an
already existing class.
• 5 levels of inheritance
-Single level
-Multilevel
-Multiple
-Hierarchical
-Hybrid
12.
Types of Inheritance
BaseClass
Derived Class
Single level
Multi Level
Flower
Rose India
World
Rajastan
Jaipur
Types of Inheritance
•Single level
Class Base{
Data members and Functions;};
Class Derived : Public Base{
Data members and Functions;};
• Multiple
Class A{};
Class B{};
Class C:Public A , Public B{};
15.
Types of Inheritance
•Multi Level
Class A{};
Class B: Public A{};
Class C :Public B{};
Class D: Public C{};
Polymorphism
• Poly meansmany. Morphism means forms.
• Polymorphism feature enables classes to
provide different implementation of methods
having the same name.
• Two types of Polymorphism
– Compile time (Overloading)
– Run time(Overriding)
19.
Overloading
• Overloading
– Inmethod overloading, a method is executed
depending on the number and type of parameters
passed to it.
– When we compile the class, the compiler binds
the appropriate method to the object based on
the method’s arguments. This is called early
binding and this process is referred to as compile
time polymorphism
20.
Overriding
• You canhave a method in subclass overrides
the method in its super classes with the same
name and signature. Java virtual machine
determines the proper method to call at the
runtime, not at the compile time.
21.
Abstraction
• Abstraction issimplifying complex reality by
modelling classes appropriate to the problem,
and working at the most appropriate level of
inheritance for a given aspect of the problem.
• It deals with the outside view of the object.
22.
Abstraction
• Modifiers:
If youwant to access a particular variable , method
or class from anywhere , then make that variable
accessible by using public modifier.
If you want to restrict a particular variable , method
or class to be accessible outside the class , use
private modifier.
23.
Abstraction v/s Encapsulation
•class person
{
private String name;
public void main()
{
System.out.println(""+name);
}
}
• Abstraction means giving useful information , Encapsulation means hiding
unnecessary information.
24.
If this presentationhelped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com