ASSAM_POLICE-GS_EXAM
ASSAM_POLICE-GS_EXAM
Date :
Page:
OBJECT-ORIENTED PROGRAMMING
(oOPS) CONCEPTS IN JAVA
Obiect- (riented Programming (00P) is a design
programming
around
paradigm that organizes software
data, or abjects rather than tuncions and
logic
Jaya is1San object -oriented language that ollows
key 00OP principles such as Encapsulatiom ,
Inherilence Polymorphism and Abstracion.
@urious- programmer
clASSMAte
Date :
Page:
Example:
class Persom
private String nameWprivate Variabie
Cencapsulation)
/ Public Qetter method for accesSing private variable
public String aetName ()L
retun name
b) mheritexnce
Inheritence allouws ome class Cchild class) to inherit
the properies and behaviors o another class
(parentclass). This promotes
DL ode reuse and
the creation CH 'hierarchial class structure.
uriQUs -programmer
Class Animal
classExample
sound)void
Dog Systcm-out-
Systerm.out
@
mmer +Sournd)i extends
|sOumd
Void):
Dog Animal prinin
printn
Animal
Void ((Animal
("Dog
Overridden
method.
+Child+ <-Parerit
Method class
<- barks makes
Page: Date :
cIASSMAte
") a
dass saund");
clASSMAte
Date :
Page:
9Polymorphism
Palymorphisrn allaws methods to behave differently
deperndng
his
on the object that invokes them.
can be achieved through Method
Overloading Ccompile time) and Method
Overriding (runtime palymorphism).
Example Method Oerloading
class Calculator
int add Cint a ,int b) {
retun atbi
Caleulator
add (int int) + Method Overloading
add (double ,double)
ki( Calulator
@urious -programme
Soumd") +chld
class
(overriding
cIASSMAte Sund))
a class
Parert
4
;") method.
Overridden
Date:
Page makes Method
¢ @
urious-pro
barks
Animal
("DoQ
Example
Method
Overriding
(" Arimal
System:outprintln println Sound void
Void
(): Sound():
soundC)s
Void
Extends
sound
()YOid System.out Animal
@Override Dog
class
Arimal
Dog
Class
features
method
clASSMAte
be
achieved
using shape")
essential icircle")
Page: LAbstract
Date
the programmer
the interfaces. Caloring Drauing
()i &
only cass: (" Shape ("
concept voiddrauw -
out-printn uriUs
can -printn
exposing Abetractabstract
cdass
Shape extonds()S
daw
Void
the lhisabstract
classes @
))Abstraction: voidsystcm.out
color
()
Circle Systm.
is abstract Oyerride
andobject wth
Abstraciom
Example Class
details
an
H
" Class: " 2.
3 public
dass classCar Example : Object
public start
void )
yearint
Classes
Carl. car
startO; Car SysBm. madel
String
j i
canand:
model
Carl .
static (methods).
properties A
An
year l.
car1
Main out & instance blueprint and
programmer -
voi=d @urias-printm
:2022i new
main perfom
actians. (atributes) Objects
"Tesla"j fa o for
Car ("Car
lcalling
methodthe (String creaking
() class
j is
lcreaing Ll starting")
snd
args) that objects
behaviourS Page Date :
IASSMAte
an holds
object defirning
data
used
initialize
to
Variable
+Instance
crended is retun
type.
cIASSMAte Car
Class object
performs
value.
:DatePage:
Method Object method
used
+ Consiructorsi
acan
retun an
a @urious-p
that have
start
()method when
Carl model
"Tesla"
=
(Object)
2022
=
year code mot
-m odel: Void
String A called
Constructor:
specal
ot does
Car
clasS int : and
() blockand
task
is and
:
year start 4
Methods
A .
- + created
objects
Method:
3.
"
cIASSMAte
args)lcomstrucor
called
25);
:DatoPage:
¬ [1 ,John"
age) String
@rious
-programmer
int ( Person
main
,
this
Mame
=Mame;
Mame agei
Canstrudor
fExanmple. voidnew
name;
Main
class
public
=
Person
(String = static
Person
pl
int
age
i Comshructorage
class
Persn
String this. public
M
instancethis
Example: instance Keyword
|The t|h4i.s
CString
model)
Car Constructor class
Car ¬ hey
using Il
Hhis instance
String have
model'
Whis.
reicns Variables
keyword
refers
is
It
nodel variable nmodeli
"model' the
-programmer O
= diffexentiate.
Same used to
sa
ismodel and this' methodand
i name.
the parameter the to
instance
variable to differentiate
between to
paranmetot
cuTrent
object
parameters
when Page: Date :
clASSMAte
between
cIASSMAte
Date :
Page:
@ uriaLS- programmer
public class Main &
public static void main (Shing Il args)¬
Counter c1= mew Counter (;
S;
Counter c2 = new Counter ()i
cl.incremernt C);
c2.increment (;
cIASSMAe
Ciate
Q urioUs -programmer