| SHES Graduate School of Technology — Subiect» CORM
H
i Aruna Popat Khalkale
Assignment No. ...2:....+. Date
ea ee =
I Assignment No-d TE i”
— Qt! oat is_meant_ by foberitance_ Lexplin Sts. Aypes in
| details votth tbe help of diagram [pmgraro. ect
Sy \pheritance 13a. concepk_in_java_vohere_in. one clase
| inberite attributes and metheds from another claxs _
nis prombles cade reusability and estabNshes_a———
| relationship between classes = ———
Roll No: 12,
“Typeat
® 'Single—Inheritante + In_single ePnberitance , one ass
inherits frpm_one_parent class _________——
4 £q- parent cha S. a. —
= clais Animals ze |
| und speak (3 § oes
pat eres Lae |e fed Systeno- out printin.¢ “Animal specks"! J -_
child class i herfting from Animal =
4 —_—_Clatt_Dog_extends Animal? se ais
void bark c19 a
——_}- system out -printin C'Dog barks!)
nee ar _
________publfe class Man 3
pa ——public_static void matn (string? Largs:
Do = New Pog a _|
= A Speak (> 5/1 inberited —_|
5 d+bartk C3; From Animal
“Gl muttTevel tobePlance: Alou fe derived roe clas
I 1 | hot 2g clio derived from another cfog
ars oe
Page No.t lass Day g sdenidy Ae ‘“ 4s
auld WHR 't
Systern Diab pr hn CD
g
aw puppy otends bog 7
pid woope i
cy tern ada, rindi C'Pungay vreps
4 j
public elas Main?
publfe static. vosd rmniv,Z
patie poppy pe News paepiy (0
poopeak Os
pe bark (95
peeps
4
"ae
Eiferarrhiad Inheritance: ene parent dass has tore than
ore child dass.
Fy! claw Animas?
votd sound 692
sypsters-ous pritdin ( “anirea) pracskes ctr
4.
dass beq eAends Anirnas 41
void bark( 4
cytes cut wprird ip Op,
‘ gqSIES Graduate School of Technology
Assignment No soo Date
class cat extend: Animal?
void meow (
System bur punt In CHlcath mens) +
public clats Mound ;
public static wid main (string [Langs )s
Dag d= new og ©;
desound 0;
d- bark ¢);
Cak ¢ = neo catC)
€-g0und (9;
comeawt>:
w= 2 83
Multiple _tnberitance »
A chfld class inberits stam mare than one parent
class: Tava. doein'é support muttiple fnheritan to
avo ambiguity 6° diamend problem. tlowevtr .
multiple inberitanye can be achieved. from interfer
Hybrid inheritance: “Lt 9s a combination of differ
| ~types_ct inberitance -
} Eq: //parent ctor
= clay Animat 2
vord speak C$
- system: au printhn C" Animal s peat
= -
= | interface. pet? :
ie iL void te_friendly ¢ 9)
a § class Pac extends
Si. 2 yoi apaak 13 8
|! Syste oak printing? Dophart
Animalimplemeas
Pets| “publ?c vod taFriendly C2? —
syste: Oub-printin ("Dog is “friendly!
jas tn, ‘ -
public class Mein 3
i —-- public static votd. mnain.cstringtiony ld
r
Eiihiinmituill ‘Deg d= new bogt dy
_ds Speak O95, Lee
a —___ds bark 69; ap
deistriendtyes
Saf hat. ?s an_ interface? yahat mle does interface play in
| taultipte inkailance, ex plain vith example,
—}p-An interface is a_blueprint of a clags. tonto ning
—fpabstrack methods thak must be implemonted by the
-claster that chanse tp_inoplemenk the interface.
java doesn’t support routtipte toherilane.thmug bh
+—Clawes fp avoid diamond problemihich oeuirs vShon
p—2-parent class have method voithe same s gnats
| Eq: jnterface Father’
void Farhorskitls c9-
>
interfa ce mother 3 _
iZ vord Mothergkjligy,
_2 : —
a classy child implements Father, Motharg
fins public yold Cathe rsy itso) Be
a SySFem out * print fn CuDriving’
2 a —s
——___publicvord motherdeilseys
——-System-eukprintly C'tsaking y
5 Page No.
ye
HSIES Graduate School of Technology Subicet
Roll No
Assignment No. 2.0... Date
a Ee leieieee ne
public aaa Main 7 4
public. state void main. estring (Largs) $ adi
i child ¢ = neo Child 95 L
¢- Fatherskills ©)"
c+ Mother skilis¢ >:
£ 4 -
g
S3jWhat Ts the di ference between abstract method /etars.and
| interface ) Write an_abstrack class pmgram to cateulate -
Pare oP crete, rectangle _and triangle. oils ey
‘Abstract clout —________Interface___4
|®abstrack keyword us: __® interface keyroord is used-4
‘®can_have oth abshact __ ® can have an only abstvack +
- I and_conerete methods __ methods = —
——}®-can have_frstance @.can_have_only pul _4
——}—variabla static finatvariables
—]@can have any access __® All_ metheds_in the 4
rmethodsand interface are public by
_} Fielde default,
——|®can have a wnatruchor @ can’t have construttor
1® Supp rts single © Multiple inheritance cau
= ance. _be implemented.
{ ‘abstract class “shape § a _ —
= ee Oe eal |
aisig- alate asteoda uehage gl wis 1 a
_private dou radius
————public_cirele Cdouble: 5) pith, lin 8
. this. radius = rs = ats |
3 _ *@ouerride 7 4 af WN
diame public_double area)? Ass
Yt ___rehucn_ Math PT rad| class Rect extends shape? — 2
private double lengthy saith,
public Rect Cdouble Length. dol
this: length s length; -
Ahi's-wid th = width;
@ override —
- _public_double crea C$ —-—_—
——__return_tength* width; — =
ar el ik a Sade
class Trangle exten di_sbape 2. -
____ Private double base, height,
_public “Prangle cazuble'ndocble FS i
______tinie-bage=by__ 1a
——¢______Ehis -height=h ____
“@overridg
ble void th) 3
(uclecle cured ref rele-aseert
iiReegae
- oystem out printinc Es ea Se.
+ s
cateh CeNceplion ©) 2
system out printin Cov,
fem Duk printing'can't divide a ne by sent D.
‘finally?
i Sysiem- oul printle CHMis ie ne finally block”)
i a
Unrw. new Arithmetle Exception ¢'Tnying lo divid
wy ON):
2
f a
G6 Whak 1s an applet torite an applet program. Ve display
smiley face
(In Sava_an applet is a spedat type of program embedded
in the web page “to qenarate dyamie contonk Te is
i: aboa clas in Tava:
—}Zapplek program. to. display emi ley
import fava-applet Applet ;
impor e povaanot 5
Public class Smiley Applet extends, Applet 2
public vord palnt COugphics. 4 12
sek Background Golor:vohu'te):
7 setcolor Ceolor-yellow)
-fellovat C109, 100,200,200) |
cy: sektolor¢ color: blaek >:
gl Pri Oval C15, 115, 10,20);
ag: FPHOVeL) C230 115,105 20%,
1-4 du hte C160; 220,100, 4a, 18,180).
Pape NeDate
Assignment No.
public. static void main (tri
Frarne frame = new Frame
Smiley Applet applet = new salnsrie
Frarne - add@pplet)s —
Applet: Init Os ot -
frame-sets “¢ Yoo, '100), St
Frame + ars ble Ctruess
Frarne addWind ow Ustener Crewjava
_ event WindourAdaplec |
@override <_ $$$
= public. vel citi ii
argo
EF Tar
gleam reat
ete
|