0% found this document useful (0 votes)
4 views

OBJECT ORIENTED PROGRAMMING

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

OBJECT ORIENTED PROGRAMMING

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Object-Oriented Programming (OOP) is a programming paradigm in computer science that relies on the concept

of classes and objects.

OBJECT ORIENTED
PROGRAMMING
Object Oriented Programming is a style of writing programs that are structured on data members(attributes) and
behavior(methods) with creation of objects.
A class is basically a blueprint for creating objects. These have their own attributes (characteristics), and methods
(behavior).
A Class can be a parent of many objects while an object is a child of a class.
Inside the class closure {} variables are called attributes(data members) and the functions inside that get or set
functions are called methods.
What is a Class?

• A class is a template or blueprint to create objects.

• It’s a user-defined data type, with its own set of attributes


Object 1 (house 1)
(variables) and conditions(methods/functions).

Object 2 (house 2)
Class (house blueprint)

Object 3 (house 3)

What is an Object?

An object is an instance of a Java class, meaning it is a copy of a specific class.


Pen yellowpen = new Pen(“Yellow”);
Classes and Objects
VARIABLE – IN JAVA

•A variable is a name assigned to a value that is stored inside the system memory. The value can be updated during the

program execution.

•In Java programming, the variables used for the program need to declare them first.

•The variable is declared using a data type followed by the identifier name. The variable can be initialized at the time of

declaration or it can be assigned a value taken from the user during the program execution.

•There are basically three types of variables in Java,

• Java Local variable

• Java Instance variable

• Java Static variable / Java class variable


class Program1

class Product
static methods

0 0 0

n1 n2 p
int
static variables
What is an Object? class Product
An object is an instance of a Java class, meaning it is a copy of a specific class.

n1 n2 p
int

Object P1 Object P2

0 0 0 0 0 0

n1 n2 p n1 n2 p
instance
methods int int

instance variables instance variables


Declaring an object
CONSTRUCTOR
A constructor is a special type of function called (invoked) to create an object
and initialize it.
A constructor is a special type of function called (invoked) to create an object
and initialize it.

Types of Constructors

Default Constructor/ Non-Parametrized Parametrized Constructor


Constructor
NON-PARAMETERISED OR DEFAULT
CONSTRUCTOR
• A Default Constructor is a constructor
with no parameters.
• The Java compiler automatically creates
a default constructor if we do not
write any constructor in our program.

No Parameters – Non-Parameterized constructor or default constructor


The Java compiler automatically creates
a default constructor if we do not write
any constructor in our program.
PARAMETERISED CONSTRUCTOR

Parameters
Parameterized Constructor

User defined function


CONSTRUCTOR OVERLOADING
Constructor overloading is defined as the concept of having
more than one constructor with different number and type of
parameters so that every constructor can perform a different
task.

You might also like