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

Core Java Assignment 01

Uploaded by

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

Core Java Assignment 01

Uploaded by

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

Date

Nme_Rahul Ramash_NAt had


Sub (ore TavCa
Std :TYB8ACA
Roll No 1

Asaigpraent
Q1had s tnfenence Hoc dose it_diffes Aron

)An inte nteaface is a collectian of abs tract


me theds.
21AlL methadsin
2) tenface ane public l obstract
by defoult
1 nten face Can include statle& defau td _tnethods.
4) Abstract Classes Cean hahe both abstract and
hon- abstra C toethods
5)Inten face alloo nultiple nhenitaoce, ohile
cibstract classes do not
6)Aclass usesey implem en ts for ntenfa ce and
extends for abstract clase
aAbstract claseg Can haueonsfructors; nfenface
araot
)ntenface _proyide full abstraction, ohile
abstrac
dass alloco pantial.
a) Albstsai classes Can have instanceyaniables
ierfaces only Consfaeb
(oY Aclas Can. implerment multiple intefa ces
but extends only oe ca
Page No. o2
Dats

2 Explain Package n 0etoil ith eKenple,


A-packa qe qtoupr ela ted elasses& intenface.
-o de
2) helpschq£nize modularity and
auoids nominq Conflics
defioe
my Packag) package Ciey fackage
4) Pata Keaes
ugesefined
-package Msing the import
alloa Controled accesS
stakemert
Coith
accesa modifens.
1)Pile structue should match the package Strictune.
s) Code ie oroanized tierachi cally fos eoy
manaaemen
q) To usk Conpile and eKecute classes coith -d
opti on
Lo) Exanple
packaqe my Pockage:
public cths myclass
publie void houl)
Pege No.
Date

Java t0 Crat
abstrac classvolumeQerire two classLI
ylinden Cont al culae Volume of 6oh
abstra ct _cass Volume
abstract double calcut ate yolume LJ

Class Cylinde extends volume ?


cobteCaleulae Yotumet'
double adius, height'
Culinder (double s double h) adius =rheig htsh!
double Calculateyolume L) fetunn math.1 odius
*Yaridus * height
class Cone ertends Volumei
double radiys hele
Calindes (double double A)
h)Q vadiuy
radus ir heghtab;?
I, hegtn
aouble calcula kyolume () iretn Math PI k Tadus
*radus heightJ/
publie cass main
public static void mein Cstring[ anqs)
Cylindencz new cylin den (1,63
Cone Co neu Cone(, 0)
System.out print lo cl Cylin der volume: " t
- Caleulake Vodume ()
S4skm. out priotln(" tone volume "t Co.Cclelake \olume l3):
cla
ccesspaseni
memhers
Refenenee
to chld
constroctn! and
Shoul
he
panent He
ininheritanee
Page
No.
method in propez yoid
Date
osth methodr
clase seUuSCability
Code t
U PanenPanent
panent shocy
pixst fenentiate
class {he di
to
Supen
the
keyo9te (
thepaneni
ble printh
conflicts
OyeGoden ertends
paLent class
yaria ínq yoid
to seenenc
out
be Poentld 4Paoent
used
a na Chi
Rsygkem
clat sS
acçe
Constnetor nool
call
ls
Lahenitnce Ercample!
to) class
simpliie
methods. Dutput
cy elaild
Avoiàe
ca
can
Super ehild
Supe 4)
Sugen
)t
3) ) )
Pege Na. Ut os
Date

Mots to create Shhng Jay a?pht mogi


Commonly used SFring neth od
oe Created using tcuo metbode by
("Heto");)
w String
) String S ane immutoble in ava, meonínq once
otatkd, they Cont be changed.
a) Commonly used sting s method inelud es
lenath iy 1- Returns Str'ng lenath
i) Subating (int) Returns subsiring
iü) chaah lint inder): Returns characker at indek.
i) inder of CString) :: find substring inde x
)equas (objec)e Checks. equality
vi) to ÜpAcage() Conyst to uppenCoe
u toloweaCasel- onyents to JoGRNCOe
Remoyes ohiteSpace

Erplain tosring method


method_oith
egoith QKample
Athe toSpaing nehod in Java is used to conver1
an objeci i o a Sting epreyentation
) EveT class in Jaua inhens the tosting
method from the obiectclacr
2) The defauli inplementation retunns a Strng that.
include the clacs name and the obiectk memoy
locoion:
u) it is ofte o OVeid den in Cuytom clasieto
Paga No.
Date

proride C meaningfulshring ep res entation


eloyeriding to String nalkts_debugg inó an d.
furintonnatin
ogging nhieN
cLbout the objec
POllngge
6) Erampleclass Student
ouestiding to String:
Stnng name
int
Student C `ting name, int iqe)
thisname me
this age any
Qoenride
public etun
Shring toßting ()f
"`tudent Name

public class Maio


publ'e Static vod maio (string[1as)
Stude SBudent new Studeni ("Iobo 22);
ltmol println (siudent.toS{ring))
The output oill be sBudent Name Joho
Aqe: 29
3) The to Sirinq method Can also be used for gtring
Concatknation implicity
q) ilsa qood practice to oyyenide to&trin g cohen
dealing youn clae
(Page No.
Duto

Io) The to SAring, method is autornati cally called cuher


Ahe dojeci_is printd or Concakenated asth a
sting
l hat is datoa-type 2 frampte Grplain ypes of
datatypey used in Jova

A datayge detines Ahe tyRe of data a yoniable


CCn Stoe in Java
2) Tava paovidey too main cotegoie of datatypeg
primitue Reteente/objec typeg
2)pimitire type inelude
- byke R-6ilinteqe
:6- bit inteqer
-int g2- bit inteaes
- long :64- bit inteqer
-float 32-bi floating pai nt pumber
- double G4- bit flonting, - point umher
char I6- bit jnieodë chanacte
-baolean Represents Ahue or false
u)eeterence types Include
- objechs
Stvings usen clefinedclasseg
5) Each pmmitive type hed a fired gize, alloxsiny
Tavato be plotfoIm independent
6) Prirmitive type do no Support methoi, cohene a
xelenence type can be objects and Can invake toy
)RefeLence {ype one more flexible as they aa
point to data siuctue and objectl, or be aull
Page No.
Data

g) wh the mainl) method ie publie Statc_Con we


the meun method?

)The mainl method is public So tha t t


CCn be accessed by the Touo Runtime énuiToment
(TRE)from outSide the class
2) The main method is gtatie So thai it con he
te Called ooithout Creatinq an instance
the class alocoing theproram to n
olthout an abiect
) t is declartd uoid because it does not retunn
Cny yalue to 4ne Caller
u) The method Sianaure is publio Sta tic woid
is
main (shsngl1 rcs), cahtr
used to oass Command-line
Stringl1 anqi
-et arquMenk
G) es the mncünl) method can be Oyenloaded,
but the IuM only eels the meibod coith
the eaact slanatuRe publc ctatic wald
mainl stringt1 arq
6) Frample ot ouenlaading
public class acuio
public satic voicl ainl gting[] arqs)
Susem.out printn("Main coith String L] cnqa")
public SBat ic yaid mainlint cxq) i
System 0ut piatla (Main with int ae:
t arg

You might also like