0 ratings0% found this document useful (0 votes) 24 views18 pagesAbstraction&Multiple Inheritance
java Abstraction & MultipleInheritance
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
ABSTRACTION |
wuicn ts vse 40
Fost
betraction ts cops principle
m~ rod .
Sp freee Only he necessary detail or essential fester? of,
i
oh
Ate implementation of te prom We
Te qava 7
t we can aetieve Abstraction with be hele
> Tuterjace .
SS We tne hetp of clase we can aetwieve Avstroabia
me !
ee eee |
: |
2 Avetraction clase can have -lwo types of Meth
UUUGUE
é
ve Sestraction +
z Oy Concrete Method
as
& Avstract Method
x
2.
—coneeers meron:
2
Be A pMetrod wie, Lat wethed implementation fe
2 ,
SU ence os | Cones [nctedl,
ee
ay NAR
5 [ moaifiers J eetarotype Merned nace (Cformat aces)
Ipjave seaserents£4 public tet dest C)
i
Sypieen ont: priontn
tn 10d
eet
("“Hrom test0") 5
p scsrncr mentep:
A Melted wliets deesn"t have method implement
Abstract
ts knoean cis” method
SYNTAX
aetrace EAS] vewumniype muneddime (Chora ange),
gesiract | public void add (inta »tnt'b ys
With Respect 40 Abstraction we can classify tases Into
eoo types
Dd Abstract Ctoss
2 Conerete class
pb aesteact ciaes:
poomecein cles ae
A class which {2 prefixed wlth abstract modifier
Emown as abstract classabstract
Class ph
N Java Chatements
Should wei mace a clase Abstract?
i
I
Da. |
PT) we trave au Abstract | methed dectared fosiole me ene
S . :
POA we. dave a6 Avetract method Tahertiel bet not oversielte
POINTS TD Be eemMeMBeRED AsouT AeSTRACT CLASS |
T
"a :
> “A betract Classes have constrictors ~
can : ;
L Abetroct classes have both concrete method & Atwstract method
y We can rate class: Avetrack even
th is mot ci) |
hee abetract method:
yr Variable ‘cxonet be abstractect
s) We carimot fnstanttate ! abstract class ie we canit create
object for Avetract’ classes : .
can't be abvotracted
ly Sbatic members
art be abstrneted. ‘
> private members can't bx Preffred Cob a “abshct
modifier
Ss bined members cant be abstracted i, tract
7 ined with Atos
A class witch [8 not prefixes
68
modifier fs Emown as Concrete cla
Conerte class cannot have carl abetrack
. methods : 7
A concrete ctass can be Pnstantiated. a é
ee
AN cess insite cose we previde implementation 45
| CU he abstract methods eed Method Overricting fs
{i S
i Know4 as Concrete Amplementing class =
S
STEPS 7D cesaTe 4 coNnceETE IMPLEMENTING crac So
nH
[STeP4: Create A Sictass “tos
the
¢
Alettract clase
\STEP2: Provide
Tmmplementation to oy the Method: C
coliick je present inside Abstrace
class ~
1 | abstract
b Ae aclass Catel
i | aberract ink add Cintas int):
f i oo
| abstract int sub Cinta, intey, : g
abstract int mut (Cinta, int b);
ebetract int div Gnta, nb);
©)MESS SEC CCCI Seems AeA) |
VUGUGCCUUUUKCFOFOOOOCUEEEGOCCECE CECE CE
. class
rere
A
elie j
Peouie int eed Cink arintb)
i
return cae;
3
Peblic int
A
return a-b;
J
Peele Int med Cint a, int b)
a
return axbs
4
Public int div (int aiiotb)
4
return a/b;
4
4
class Driver
4
public static void wenin (string (9 ange)
4
Calculator C4 + new Catceslator (+
Sb Cinta, intb)
ie
tm
Gopla(es- ate C10, 20)
+ (cs. cub (101 209
(es. pat (1072055
(os tv (oe. w)s
GeEQ2 i abstract clase Laptop
A
int jas
String arm 3
doable price;
loprop C4 § ‘
Laptop (int ia, cae ram, double price)
. ‘
Atus.ids ids $
Ahis- vam. vam; ;
this. price = prees :
n ¢C
Absiract Vold ce plas Dererils (> ; ;
i 6
class Lap extends Laptop [lad constructs ¥ S
ro Lapoody 2
| Pee leer ctieplasy eee ytar Cine fd Saring ram, double pi
| . : superll, vatn pice); ©
get out piatle (“ro Of laptop i + id); :
/ Sask cut prinktn (“eam Of Laptop?” + ver): :
| S
| Begsiem: out: prinkln (“price ol Lapion
ra P P ‘} Laptop eS
i 3 7
; 3 :
| dass Drivevt -
i § .
petblie static vole main (seeing EI erae> e
| 4 oO §
i Lap “ibe neo Lap ( whos, 4ge", e000) ; S
©
| cae Ateplay Details (0 S
€
5 §
«
Jig a Keysooret i us
aebie
ra ipkerfoce te a user olefined
LE MUbet te. obed 48, Jaduiéve’ Wbaple -areiert tence: Guts
Re
|CREATE INTBRFACE
)
) NOTE |
; re ; |
i Pd ay defasut interface fs an atsetrdek member |
> y We cannot create an Object don interface.
: dWe any compile an interpace & Gerretse tase ile for
) Aho
i enlatel TE. ctase
' (Farergace ss Fever face TE
; i jooe :
>
> 3
>
> cf we an inkerfoce t. 1
: By We exnne mace € ctther private oF
> 1
> protected Se cam Pe ether de pactk oy pablic
>cannot mabe an inlerface oF
can have inside Interface i
we can have
£9: interface r2 “4 . 6
1 } €
PUbUe: static votd main (“string Fiard, :
: d age é
Salem our: Pantin (“Hteuo wend”): : *
5 poe 1 ¢
a ‘ Hetlo word - €
With he above.
etample we can fq wo important
£
oO
can dave Stotic methods tnetcle
To terface
We cen erect i
; ett, tne interface
|
? pie pubite abetract method.
ee me
1
leq. interface ry
rt 6
t 7
g
| void test 005 llers =
é
| ; <
| ey defoute the fet method insiolé intesjace ay
:
| ; <
| uau be prepimed we partic & abstract modifiers
é
i ¢q
d
: 4
ea. implements - Ly
COoYUo?e
wwe yw wow wenNenuwuw oe
PEPE ce pone server te prpined
4
void Lest)
t . :
Sip ous. proken ("Implemented insicle clase ads
4
na
“The dlbowe preqren te 7 +o Linrod> ‘compile Ai oe i
emer sauging an 4o cestge weaker access |
prvsieger 1 wey fuse! ust meme teaser of MPH
member |
member ie toterface a wes o pablic
Sy public, statte & —final variable
interface 26
a
int f= 407
puiic static void main (sting 0 org)
4
Gece laa (195 ets 5 sterig variable
f= 205 Move — -firal variate
lee colle pectelic
By depoute vexioe 1 “iM be >
gieric & faol wtedittersMembers
oe. met tare site
ee sarret nave insid
Mou-Slatie
PF Concrete metnoete .
VAtimat mm avctact methods
® Non- static wavable .
™) Static block
DS Non- ctatic
block
© Constreectore
> private ge
eT INTER RACES
IER Feces
Note
|
PTHe static Mmernode oh tnteryaces
betract methods a ne
IU be inhewitect.
I
Bhs coop some g
Bolerface 71
a)
|
|
peblic static tina
Interface
wate lever =
Entenfece +
pel Tobesteal
Varicctles
Favertacce as!
5
Toten a ce a2 extends
i
j
» LD )
ANAND D
MAAaAdananaagagnane
&Au Slerdoce
UH Aine
6A Puteri ows out or mor intel] aces
aig Ret ple Beteribaiee
fMterfoce Ta
1
i)
futerface 23
4
asa
|
. |
‘ep “h * extends! Requeord |
extends Ts, T2 |
CASED: Class camaourd -from Aoterface
Pp A ctass
caw inter bow an Deterpoce 2889 “Implement:
“phesitence EA. ke pre
jusplement is ve presen sed
VANE dotted OneDA class can fohewb. fromm
fg: Teterfoce: 4 ctorertace 32
a
class
Tutoface 26
t
4
Interface a2
i
i J
i Amplement
close oo MTF ay
Is
|
4
BA tase can Teperik from one efass @ o
class c
eng Member of
inter:
Cceg
Hac) wee} thtex aces :
ARAARAAA FE. i
= ae 3
acs 0 extends
ote iy
NL Wuemever &
ie ctype. of meres
& —
i
> sD po Aotijarce
os” 7
Tobe ®,
jor re
Implements
class
ie
O clase
MUSE olecoys mabe scr
Implements »
lease: A
4
T4, To,
as
Place
Gene o from «cla
wen
vse
es
in Inhewting trom both, tne
tu lrerttace
+oMULTIPLE INHERITANCE :
HH Java,.weeetiple Tutresitauce be Pertible woth Yu.
sheep oh Nema] wicuebers
P Onty Fuerfaces i ‘
» Combination } Class & ‘Soterloce (
pL OCR Mi cieecr seen ; :
malls Ble TM tence ¢
Geturved | we cau co.
pvere one
ponent “ype late
parent “gre top ont vemplretey « . 7
Onthhes
ePrice ,
wr ‘
if Downcasning [ty PE ‘
| CASTING
|
clase G
class A . euper wesstber being an
if : ss P 1
: . / interface & cco member
J . ; . being @ class is atm
{ Futerfoce B positsle jor" Non-paimitive
i 4
Agee casting.
class © eteads A implerments 8class Drver = aoe
t
ee static weit wain Cetnngrs og? .
© ob}= new OC) 5
B objt= (ey obj 5 7 urcnering
CO) objL 5 1 poton casting
5 Couversion PY OPS parent type inte anotner portot taper
class Diver?
f
Public shane wold pain (String ca args)
a5
A objs new ACs
& obji= (e ob] 5
ob} = Cad objts
4
’ fg whe pragraw for Below Requirement!
interface ere
> f Wwitadcaw Hacking
Deposit Mactine
t deposit: wltadea BOs
-Untertace Deposit Grit mas
i
Made kéve
( tier fuk depostt ( fuk aut) 5
5 : —o
‘setdace bot
4
tk
Had rat
witharac (tae ames
4
clase
t
Prposttanet WithdracMaeuinee
Emplements Peposits Withdraw |
> fue bal 5
c)
Depostt And Withdraw Mackine
t
4
publicitin deposit Cint cmt)
bot= bal+ owt;
“te bay PRP Ete C Accent “balance "4 bat);
rebwen boll 5
3
Patel te wsithedracs (tap amt) :
{A
| 4 Cam > bar)
joao amt 5 : i
[clans eubspantte (Mo ce fficiine Guancet)y |
lara Bet print ("Account balance "4 bat);
churn bal; . '
\
J
\
J
lass Diver
Pablie vestatic void sata Cstring 1 as
i
Sn > new ~ att posi i
Depositand yolindrowMaahine D4 0 ~Wltbed Depesil Aretto
2
draw Mactine(DA. dleposte ( +0000)5 oH |
D4. wottha race (2000);
3
4
class Dwyer *
<
rete Static void wuate (string 6) ange)
ene.
Deposit ma = new Deporittind withdraco Mactine CIs
ros. deposit (10000) +
fae Withdraw) mL), withdraw (2000) +
je.
on
sce tattle
dass! f
\ DW Hactsne ‘
deport lite
in
whiudraw Ale CATH)
| coittdenut
Eeweap mport!] orpausce’
Oly svat eo qoute = cud to do Impo ee
cole do daetr gy postiustos line
[Ae yeaa shottut tp “pen Yee OpHicle one
Avot cet 45 provide “getters cxl + space
Command 4p ong Hee emo cba sr
Ant Joni
incacase.
AN = ont decease
Source 3 Mita Mende oP Hone wm qettee, settee, Comte etsy, a yey.
3
fi 0
ide
OY OY 0) 0 0 0
en
A
bi
aa
adnanaa
OAAA
Mm.
AnRAAAAAD