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

Java

The document discusses various access specifiers in Java, including public, private, protected, and default, and their impact on class visibility and accessibility. It also covers Java buzzwords, encapsulation, inner classes, and the differences between compile-time and run-time polymorphism. Additionally, it highlights the principles of object-oriented programming such as encapsulation, abstraction, inheritance, and polymorphism.

Uploaded by

sathwikreddy1731
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java

The document discusses various access specifiers in Java, including public, private, protected, and default, and their impact on class visibility and accessibility. It also covers Java buzzwords, encapsulation, inner classes, and the differences between compile-time and run-time polymorphism. Additionally, it highlights the principles of object-oriented programming such as encapsulation, abstraction, inheritance, and polymorphism.

Uploaded by

sathwikreddy1731
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

| - ASSIGNMENT

(Start Writing From Here)


CMR
OUP OF INSTITUTIONS
LORE TO INVENT

)ohat a t access specAs n Sava and hoco do they


affeet the visibiUty ard aciessibity of alass membens
the accesS specifr Ceywods esed to de fne be
o isi bty f classes, eviades, ethods ard
oeuaccees
Costctos. Tieoe ate -oc acce ss specfenc in fava
Lcc SS Specffen allous me mbers to
be aceessible fom any o the laes.

2 Prrotected : Pootecte aQccesS Spefe alloos embes


to be a ccessi ble cofn He Same package
Sbelasses Pon dEfevent prctages
3- default (no spec f ) : Defautt access Specifey allos
membens to to be aceese? ble ony woftin the Same actage
4 Pofvate ;Po vate access ess Specffey estsfcts membes
ory
to be acc e6sf ble ony ufthn the Same class
Iese access
-latio ad controlmg
specifes he l s fn
aciess to
enferctmg enaps
di tfenemt p t
pogam.
Access Spe ifeHS Im java contoul bo th the access?Gty ard
Visi biuty f clasS ombes:

1- pubic . mermbers declaed ac


publre aHO nccessible fom
oy other class, egand less q the package ttey beleg to.
tey ue igible to cla sses octside the Package ceobee
tey e efned
2Prsfate nembes declaNed as Pivote ae acess? ble ony
within te game class5ey ue mot igibe to
CMRIT
MR
poF INSTITUTIONS
PLORE TO INVENT

classeS and Cannot be accesscd


outside the lasS, not even frm Sbclasses
He aCessThle
3. Poteted: emb¬HS de claned as pootected
dfeent
tft fo te Sa mepacage or Sbclas ses
packages They e visible to Subclasses nd classes T5 fho
Same pactaqe but not stble to casses ocets ide tfhe
Pacteage unless ttey a Sbclasses
|4. Defaut: mebexs delaed wfthoct an expuct cCCes5
Specifen e ac essf ble omly oithfn tte Sae pactage.Thsy
ae mol vigf ble octsde tr pactage, eLen to Subclasses
fan dffferent paclcages.

what s mean by Java Buzzwds ? Eplain then.


ln Java programmirg buz2eds" efer to key cocept
often bighlyhtcd or emphaszed teteo
0 feotwee tthot ane often bighiqhted
Aiscussing the lanquage. These buzods encaglale tte cort
pinipes ard tergths ef Java- Hee aNe Some q the mai)
Java bu2lU0ds aund thefs exphotions
1·Sfople :Javo is destd to be Casy to leaun and use. t
avoids Cooplex feteés abd Syotax found othe
larg ueges, atfrg it acessibe To a uwide garge g
:
derel
2. Obect -Oieoted Jave is tue- object
ofented sog
classes, asDanged Ym pactages &suppols feates such
ac clacseS, inbutarce,
encopscan ahd polymephsm.CMRIT
MR
JP OF INSTITUTIONS
KPLORE TO INVENT

3.Poetable ; Javo pobgYams Can du5 on aby de vice


plattosm ui tha Tava Votn mochfne (Uvm) ostatte d
uthoct Deeding to be ecODpled.
H- Po bust: Java fs desRgned to be gobust ancd oelae
of t f e t e s Such as otot memoy maogement,
CXcepton handleng and type chectpng. these featunes
help pe ent CTO
5 Secune; Seceefty is a majos
majes Correnn
ceTon n Java deelopmtnt
Ihe lang uage includes buflt? secesety feotteses Such
as byte Cacde veufcattyn, class loades, and seceesepey
manger to pote ct
G. HigbPea foomance; Despfte befrg an fntes pyeted languagc,
Java achic ves hígh pefoemaoce thoegh ftattoes (te
Test -dn -Trmc (JT) Compil atn,uhieb toanslates
bytecode foto matie macbine code at untfme fo fastey
eeutío

4 muititreaded ; Jova Suppeats multrtrseoding, allewing


Concwent eaec ctun ¢ mutiple tHrocads wftbn a sfngle
poogam Thie enables deveopexs o Ceale effcot,
9eSpoosi ve appMctiuns Can pecfoem multiple tasks
|6. Dyramie; Java Suppets dyramic memeiy allocatfon
abd gau bage collecttun, ohieh aetomatfcatly oabages
emgey usage and deallocation, This belps Simplfy
emey management nd geduces tho st of menmOy
(eot s and se9 mentatin feetts
CMRIT
CMR
GROUIP OF INSUIUTIONS

buh
3)| wbat fs ehcapsulattom n Java and botw does ?E conto
to betes Softeoae desian9 Aditorall9, could yoo epain
packoges fatate encapsuletion io fova appcatong)

data (attsibtes) and oethoot Cfancttons) that opeae


the data 'ofttna simale urst, typica(ly clss
Encapsulatton Cantsbtes to be ttey Softeease design by:
1.dwafty khcoupslated clocses ate Seif cotalred
its, matfag ft casfe to undestand and mainteio the Cede
Charges to the nttena irroplenoentatfon ¢ a cla ss Can be
maae usithoc affectfg otthes peets ef te poogam
2. rfos matfos Hdlog: Encepsutation hides te fnteena
<tate f an
obfect föum tte oceSde coosld, atloco fn4
Centlleo aCCeGs ly tÓUgb wel- de ffned Rntefo ces
fs prseents uníntepded modifction e data ard enswHES
that the obect's stale eains consisteot
B.Se ubsty : By conto |Leng access to dat a,
hetps so enforcnq secsfty jelfcies and
encepsciatro
eient uathe
-2ed occess eR modifatín e sensitS ve
ffenatoo.
Packages In Java fa ciUitade encapeatton by pooudi
a cway to orsganíae clacses ibto
elated classes togethes wit5in namespaces.
By qopfmg
can en
pactages, Jova decelepeas
force enapgUatror at a bfhe level Access
hdifens CFke publc, pro trcted ard
se Hne eneapsulatton wittn
ovate futte
pockages by
Contoullg cohich
CMRIT
CMR
GROUP OF INSTITUTIONS
EXPLORE TO INVENT

classes and merobens aste accessble to otheu classes tothin


the Same package os from ertte nad pactages This atlaos
fos he tter Osganiaatim e Code, educes namfnq Conflcts,
and enhances co de mafntefoabfty and geUsabiy.

H) Denonstvate Tnner classes and all e b types 9


dnne class efes to a lass that fs delaued Pnfe
class Thee ae ttaee types ef oe classes.
(- Nected dnner elass: can access cby pofvete ?nstarse
vauiable f tte otey class. dke any othey fnstance aade
Can have acess modifer prîv ate, proteeted, publ°c
and de feult mod fe .
ka: ctass Outey

publtc vord shoLw C)


System tret println ("an a nested sloss metto d):

class nain
puble salfe void maln (sboing anqs()
Outer-oner in newo ote(). ne Inner():
in: showt );

output : tona nested class methd


2. method docol ones classes LhneY ClasS can be
declaed wft n a methd f an ete class.
CMRIT
CMR
GROUIP oF INSTITUTIONS
EXPLORE TO INVENT
IN

ctass Oeteu
Vofd Ote Method ()
thod.
Oystem. out.pfntn ( ansrde octen me
ctass nnet
Votd nes ethod C)
Systen 0ut pofotn ("dnside innes Me thod")

y n e o anner),

class method Demo


publle stalfo void main sbfgl] as)
utey X Dw b t e c ) :
X- oeter method ():
octput psidc ote9 0etbod
nefde ?one netol
3 Anorynous nney lass: t ís deelaued wfthot
any name at all hey
Subeass ef the specifed tyPC
fmplemnenter ef tbe specifed Snteface
impeu favatil.*
cfass Dem
votd showc)
Sqstem. oet pintln "am (n sh hoettd 4
Supet class"
CMRIT
CMR
GROUP OF INSTITUTIONS
EXPLORE TO INVENT

class lave 11 De mo
Stetic Den d De Demo () {
vofd shouc)
Supenshoco ();
System. out-pâptn (" Fam in Favouwn 1 Demo class)

publrc static vofd maln (stsngC] angs)


d. showol)

outpt: dam fo shoco rmethod et SupeH cless


plavoun 1 bemo class

5) Df{fevepces bekeween Compfle-Teroe Polyophism and


Run- Tne Pelymophs).
Comple Time Polymepis Run Tiroe Polymopben
1. Also 1. Also ho on as mett

oveH Loadfg
Q. OccetS deenq he Occeeses desena tte execatir
CoTnpitatron q the proqram ef the pgam
3ReSolued based the 3. Reseled based on the
mettod Sfgnale actuo ty pe the obfect
at enttme

Custoaable
Custoaatio
CMRIT
CMR
OLPOF INSTIUTI
EXPLOETO NVENTTIONS

5 nequhe nbeatye G. Regufe anbetance


Does not
G. Can be pe foemed usfy Can be putoemed ucing a
melthod cofth
mult°ple ethods with the sfngle
b e e and be Same
Seme hame bct dfffeenl
PaameteS Paaneteys

E pooidcs fast E podes sloco


execetion erection.
8. Th s fs eSoled by the
Cempte tHe complesy

6)
piffeenes betoee
betoeen GupeH and Tbfs key wod
Supe ()
|: Scuper () 7epresents the |-thfs()epesens the
CuTent nstence of a Ceigsent Rnstence f a
pauent| base class class
2: Oced to CaU the default 2 Used to col tte default
onstuctos ef the pueot)onstouctos the Same
base clacs closs
3Used to a ccess nethools 3 USed to access ne thhods
e the base class
e tte Cusent ctass
Uged fo pofnbg the fo pointing the
Supecass fnstence CurIent class însace
5 must be the frst |5 must be the 4fGt
block. ine o a block
10 CMRIT
CMR
PoF INSTITUTIONS
NPLORE TO INVENT

Used fn ComsuctotsG. USe o Cooshuctes to


of chfld classes to foRializecatl otbey Cornstets in te
paeot ctss membens Same class to avee?d Code
duplretioo
4 Used to fnvoke the Used to ovoke he
Cenctuctos patert classConstou ctor of t e Sam
class

)wbet ate the fow fllaHS f oops and eplain wft


Gelevnt kamples.
Object -Oiented Pogeming (oop) is a pogramm g
hat DEVolves ashd the concept ef obfects, ohich can
e thouq ht of as Seif-Contained entftes. the fo

Pflans & 00Ps ae


| kncapsWaton; It efens to the bund Lng daa and
rmetho ds tat Operate on the data into a eigle urit o
clacs &t belps ?o data bid ng and 3educes System Compley
Publl clacs sterclent S
private staing ha me,
publfe stig getameO{
DetHn Dame
pubic void set Dame (stsg nam)

11) CMRIT
CMR
GROLP OTNSTITUTIONs
TONENY

2. Absta cton : u meas Hiafg te coropleY mplemertott


detafls and sbocefg only tte necessaty featues
obfect:2R helps tn acducig rga mming npietty and ef
absact chss Ani f
puble absact Votd animal Socundl ;
Puble void slee pc)
pfntln (" 222");
class Pig extens Anfmay
Pube vofd anf SoD o ()
System out pofntn ("oee wee")
class main
Publie stalfe void maân (sting C angs){
Pr mp - he Prg(;
mPanimad Sounal,
1 mp- sleepc)

3. inbesetance: dt alloos a class to fnhesit poopeties ahd


bebaviowy fro ano hes class.
class.t
Et poonmotes (eDde
tode
Eugabfuty ad log Ped osganzation e classes
class Empleyee {
float
Sclay4o0,
class ooqnammey e ferds
nt bous (O0; Empleyee{
pube stalle void matn (stsirql)
an45)
Poogammes P n o
Pgramer() CMRIT
CMR
GROUP OF INSTITUTIONS
EXPLORE TO INVENT

Sy stem. ceut posntln(P.Selauy t+ p bonus),

H- Polymerphism: allocos objects to be tseted as


tnstences ef thefn paHent elass- Rl alloos methods to do
dffesent things based on the object that s actiq upon.
lass Bfte

Zystem out. pontn ("Runnng'):


class splendlo enterds Bte{

System. out pöntn (" Runnfng at Go trol):


publle stal'c vofol mafo (stngC] angs)3
BAe b: ne co
Splendog (,
b. un0;

obat ase the types o inbeitance9 Fapla¯n tem


ustnq Delevant Famples

CMRIT

You might also like