Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
33 views
15 pages
Non Primitive Typecasting
java NonPrimitiveTypecasting (1)
Uploaded by
2004213
AI-enhanced title
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
Download
Save
Save NonPrimitiveTypecasting (1) For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
33 views
15 pages
Non Primitive Typecasting
java NonPrimitiveTypecasting (1)
Uploaded by
2004213
AI-enhanced title
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
Carousel Previous
Carousel Next
Download
Save
Save NonPrimitiveTypecasting (1) For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save NonPrimitiveTypecasting (1) For Later
You are on page 1
/ 15
Search
Fullscreen
NON- pemmitive Tyee CASTING - ———— 1 + “The process oF Comet ea ors primitive type @netmer — non-parnttive type wee cat it as Non- Pprmedive *yPe eons Non: pyimitive tyre. casting fs not possible netthes mplictttey nor epee for the etasses cwtiich( doesn't rave ong rHationship biee them 2 : > class Driver + 4 Public statte vole maim Cstrng £3 a a a A obj= eco biO> Bobj=—nrewe SEY } 6 obji= obj j Nere implicit conversion not 3 poseille.class Driver? puctic static voto mare Cstring 11 age? 4 A objs new AC)5 B obja= (er obj/ dcr Nore: Wwe can convert One Neon: primitive type +o anower Non- primitive oP onty when we have & lek relationship bexween 4wo classes “the Non primitive type casting ts peel te ine below situations: ) Lhenever we howe leh relationship beteseen -wo ctasses Lohenever we dave 3 2? common — ctrild-[Meuti ple Anvre niteanceint g te105 3 Class B extends A au int GR = 205 3 class Drivers t PeblUc static void main Cstring ci args) L & obj: new Bc; Sgplers Cut: bin ten Cobj- \)5 Saplees out printin Covj-2)5 a ob ja = ebjs me pectoe™ “prokte Cobj) ; SGM printts Cony ay, System ok prints Cobja.4); , Sf: Cctiprinktny Cobjt- fs Jere 3 3 Do the avove ample we aye Sorversing one non. veference type I pumitive hype to ANolh ew Wherence] Ron pamitive fy pe bey we have ls-a relationship between bork the classet the Mon prinnih ve Aype casting can be Classified into -tewo types 5 > vp casting 28 Decor cashbee casnngq: The preset of centerting sus-clase. reperene Aqpe tote Sepers class vefenence teype fe povon Uprensting. [etutd te parent conversion] + Vpcase aa es aise Emown as Auto class & 4a lot 42202 4 clase Ay Pablic static vera a Deiver 2 man Cewring 63 area) e&j= neces Bc; obits bls Hers Cp easing ~ dene Soopers ebjee : 7 J 2 METS = opcmsting ~ clone implant Deco BoD wee wrens / onsen ee ee we “Pp cast One 7 : eho) alot AYE Se et nee ek cee eee, ctnte mentors —vettn ays betp oy fuper clouswefevince sy class 8 ‘extends A a i class pavers i puble static vole 1 main (sting (1 args > © ovj= new #095 Sy item oak prinktn (obj) Sythe out priotte (obj: A objs= obj: System: ect: printtn (obj); Sipsieuns ok priotte Cony 4): Atysletas cot printte Conj.t. 1); — eck prinkts (ob)4-j); //ere a) NOTE: 6451 OTE: Asem cut Prtottn CobJt. J) - In ine above pgm , we wit have compile time error instreection corHen aboee, wolich can be explained cong > Wtkh athe S555 555 5 5.5 5 = wiaeaeteereote >Geer i class B “extends 4 i int j= 205 4 class A 4 int is 105 D s class Divers i Peete crag. main (string 63 ar: 1 ? & bj new Bc); Satie. oak ade XO ipys Sapper: Onk Printtn (obj Js A obj1: obj 5 Siler: ont. printty (oe); Spica ot Print Con), Nother ook prtotte Conja. Sgptenu Oot Pri nhl Couja 4 Ds. “po Vere y NOTB. Ouk: pai jas ate qe es Prinkin Cooja p — Sn Ame above Pm we ast "e compile 4, | TOY because of se hie inetreection — covitien ee *2plaineey poe i Oe Of the fottoevin, With Abe het, Pt Semantics =. LL Srrtice obji-jSemantics ceceeing 4 cleore” example, WIL chean whebber the ~vasiatle te present tnotde obs Ayre fe ctase A. ametcle eee tee aera J orether clectared nor Tohemted, dtence we Gr Compile time Error. 2> hh the heey ed Se Sf Super class Namatles .: b9Ihenewer we have reference vwanriables created ty for a clase fs fnvelvecdt en 1s-A Wetakfonship eit other class , that reference vaniatl wth hace the wisibibty ont to te members af tle class as wet as ths Seaper etass. De wit not be able +o see the members Cf fs ea class. 8 @ wo -- 7] Members of object i class 4 eee omens ap apes] CHEETA ype OF Sup ctass tteF Apvantage of UpcasniNgi ’ Ui eating hetps 0s te create a generatisec! container £4. class Banke cu 3 Ineide etic we can store ang ef tne cuts class wefrences Sp oe centr tne cele havnt a ean Betoco:- Ce eal eee oe bene eee eee ee Accounls inside tk. ie Bante Object and account | = TT -ine ctass bark we need +0 create a container camted as OL which of aype accounts 4 pccounts os lliys |] inarivg reference Variable sh ass Accountlass SA entends = Aecorsnts aad name> SAOEI- Sa (string name) t Ahis s names name: 4 class CA extends Accounts ; = 4 class La 4 5 class priver 3 t ettends Accounls Public staste vold mein Csering ang) ae Bank obf: new Banel)s Byes out prin ttn (obj-at)s [Joes ebf-at2 new sal" Sheeta"): a cece eat printtn (oby-at)s //sa@iot Obl at= nee CAC)S Eyes cet: printitn Cow) a4), MA ca® (02, cea, = new LAC)? Agee oe printan (ob)-84) 51 @ 103, 5BOTE To overcome the problem oh Cpeeseg we wi ge jor Downs casting PB pownte casting + tS he process Ph Converting Super etass reference # Tape foe Sub ctass reference “ype tf Enon ae. | Dewn- casieg anes) weit never happen implicrity + use cote ‘ qe oe 2g: class i intizios 5 Class B extencs A a int jenos 3 Bisse) peveral t pubGe Static vora mein Cstri c 0903 ar : J19 args) A ebj= new BC): /Jers > opcasting B ebjt= obj 3 Vers > Boee esto. 4 3 Nore + Down case must be done huss Bis Abe operator ctype castdass B 4 ink j2203 3 clase Drivers { Puelic static void main (string C1.arge) i A ebjs new ec): B objt= Ce) obj 5 lets. - Bowen casting. clone explieztty F 4 4 b ADVANTAGES: D The mein advantage of Pew catting 2 we soit be able 40 access tne members 0} Suciass 55 : iq: class A aps ame ink intoz z 4 clase @ 4 tat fe20s y class Driver 3 4 Pubize arate wath mato Cote teaues: A Geter atte A obfs neces ec); fe N84 steu-oeuk- printer 4 Porte (Oe 1) Hore bez cannot access ‘ Bub class member am eupercta B ob}t= (8) ob}; veperence. - Sgiiem: out priontin (on ja.t) ; \ sHvUHvVYUVUUVLUYW Deaweacee: D> Clase CastPxception : Pion Te ts a men ene preblern colic occeers dering ' Heeen cersting, 4b Abe Created object ! ane members doesnt hare the members of eub-class Note ; NOTE + yo {it Masecast fception, we mest create Seper class obpeck DYpse bere to downcas dow, © the superclass weyerence to Sub-Ctass we perencel, ‘ Eq) clase A a int f210; 4 Class B extencls 4 a tat j= 203 3 class Diver 4 a Aye pumice static vote mein (eeringt3 ar ) : ao Syflene: Ont: printtn C "Man Begins), A obf: new aC)s Popes cae poten C1), B objt = Ca) ovj : HU doconcasting Br ~ Llase Cast Ergeption Ligilen o8t- printtn (99; Spur oUF: pr arto( obj 46J);sOe can avoid Glass Cast Exception by eee shetiner the has he — Insteance ef & particatar Clase befor Operator Emoecon as * tnetanceof” ie mene Lo y instanceof + te Oo Keqeoord - Te a einen ererator ts used +o etiecte wihelfher an ee bees instance O particulary class oF not ’Crmerm bers) - The reterrn AYP] e4 Enstanceel operates ts boolean. MOTE ‘Wwe can eneoe sme instance of O. portation class get if Aime creattect — olsj ect reference type ee th Bictass 40 turin we ave shearing (@ te viog “eon relasttonstup. + Glee, we tt cre SYNTAX: Object reference Inetancem$ Clasentame =ee ol oeseet Feorr caerorT Lorre) — Favava] élass object i 5 ete tiedt ceeds object Class Carrot extends Object 4 i 5 4 class Apple extends Areete class Guava extends. rath A t 4 3 class Driver4 4 peblic static vetd main Csteing 3 args) ts Frait obj= oeew Applecrs System cae prinktn (obj instanceof Object); /) tere, Seer: out prinkte Coby Instanceof Ereeit) 3 //tere faster ou printin (obj instanceof} Apple): Ure 7 eile: prinktn (obj instanceof Guava); U forse Sgtermoust pantte Cob) instanceof - Carrot); (ore“class Drivers A pubic “static void main (string £2 args) 3 Object obj = neco Apple 03 S-o-pte (eb] Instanceof Object): true opto (obj instanceo} Feceit)s Were Ss0-plo [ob] instanceof Apple) Wire S-o-pln - (ob) Instanceofg, Guava): // forse S-o:ple (bj instanceof Carrer)s Ufatse- Apple @ 100 object pegs a jaa NEM of Object obj ! Instance ed Arie p oe Instance © { Apple | u ACEC OR URURURORORC VEU yy ot
You might also like
OOPS by Rohit Negi
PDF
No ratings yet
OOPS by Rohit Negi
8 pages
OOPS Handwritten Notes
PDF
No ratings yet
OOPS Handwritten Notes
20 pages
Java Notes
PDF
No ratings yet
Java Notes
174 pages
OOPJ All 5 Units Ninad
PDF
No ratings yet
OOPJ All 5 Units Ninad
118 pages
Java Unit 1 Part 2
PDF
No ratings yet
Java Unit 1 Part 2
72 pages
2nd Unit Java
PDF
No ratings yet
2nd Unit Java
51 pages
Part 2 - Java Programming Intermediate
PDF
No ratings yet
Part 2 - Java Programming Intermediate
30 pages
6 - OOD4 Object, Type Conversion, and Polymorphism
PDF
No ratings yet
6 - OOD4 Object, Type Conversion, and Polymorphism
73 pages
C++ - Introductory Notes (Part III)
PDF
No ratings yet
C++ - Introductory Notes (Part III)
31 pages
UNIT:1 Þashath: A Pupiam
PDF
No ratings yet
UNIT:1 Þashath: A Pupiam
49 pages
Multipleinheritance ObjectClass
PDF
No ratings yet
Multipleinheritance ObjectClass
14 pages
Abstraction&Multiple Inheritance
PDF
No ratings yet
Abstraction&Multiple Inheritance
18 pages
OOPJava
PDF
No ratings yet
OOPJava
5 pages
Lecture 7 Classes Inheritance and Type Compatibility
PDF
No ratings yet
Lecture 7 Classes Inheritance and Type Compatibility
28 pages
Java
PDF
No ratings yet
Java
11 pages
Mod 3
PDF
No ratings yet
Mod 3
21 pages
Unit 3 - Relationships
PDF
No ratings yet
Unit 3 - Relationships
23 pages
Polymorphism
PDF
No ratings yet
Polymorphism
8 pages
DocScanner 26-Dec-2023 5-08 PM
PDF
No ratings yet
DocScanner 26-Dec-2023 5-08 PM
59 pages
SUMANjava PDF
PDF
No ratings yet
SUMANjava PDF
496 pages
COMP2006 Lecture 12 Casting and Operator Overloading
PDF
No ratings yet
COMP2006 Lecture 12 Casting and Operator Overloading
45 pages
Nptel Docs Week-7
PDF
No ratings yet
Nptel Docs Week-7
12 pages
Oops 03
PDF
No ratings yet
Oops 03
14 pages
Adobe Scan Jul 01, 2024
PDF
No ratings yet
Adobe Scan Jul 01, 2024
12 pages
PPL 2
PDF
No ratings yet
PPL 2
5 pages
NCC Unit-1
PDF
No ratings yet
NCC Unit-1
25 pages
Imgtopdf 2909221401056
PDF
No ratings yet
Imgtopdf 2909221401056
39 pages
Adobe Scan Nov 06, 2023
PDF
No ratings yet
Adobe Scan Nov 06, 2023
20 pages
JavaQbank V2
PDF
No ratings yet
JavaQbank V2
16 pages
OOP Practical
PDF
No ratings yet
OOP Practical
30 pages
SUMANTH Sir.... J2EE PDF
PDF
No ratings yet
SUMANTH Sir.... J2EE PDF
496 pages
Oop Concept
PDF
No ratings yet
Oop Concept
33 pages
Java Focused Short
PDF
No ratings yet
Java Focused Short
28 pages
CPP Notes - 02
PDF
No ratings yet
CPP Notes - 02
30 pages
CPP Notes - 03
PDF
No ratings yet
CPP Notes - 03
30 pages
Opp's Assignment2
PDF
No ratings yet
Opp's Assignment2
12 pages
Oops (Notes)
PDF
No ratings yet
Oops (Notes)
5 pages
Java Assignment-1
PDF
No ratings yet
Java Assignment-1
17 pages
OOSD
PDF
No ratings yet
OOSD
20 pages
Aaryan Roll No77 Assignment of C++
PDF
No ratings yet
Aaryan Roll No77 Assignment of C++
10 pages
SUMANTH Sir.... J2EE PDF
PDF
No ratings yet
SUMANTH Sir.... J2EE PDF
496 pages
JPR Unit 1
PDF
No ratings yet
JPR Unit 1
42 pages
JAVA Middleware
PDF
No ratings yet
JAVA Middleware
34 pages
Vasit Java
PDF
No ratings yet
Vasit Java
10 pages
1SG19IS043 - Karthik Bharadwaj.P - OOC
PDF
No ratings yet
1SG19IS043 - Karthik Bharadwaj.P - OOC
17 pages
Exam Java
PDF
No ratings yet
Exam Java
21 pages
Classes and Objects Part1
PDF
No ratings yet
Classes and Objects Part1
25 pages
Dashrath Nandan Java (Unit1) Notes - Alasso
PDF
No ratings yet
Dashrath Nandan Java (Unit1) Notes - Alasso
11 pages
1683044825934
PDF
No ratings yet
1683044825934
5 pages
COMP250 Cheat Sheet
PDF
No ratings yet
COMP250 Cheat Sheet
2 pages
OOPS Notes ? - Removed
PDF
No ratings yet
OOPS Notes ? - Removed
20 pages
DocScanner 30 Sept 2024 2 33 PM
PDF
No ratings yet
DocScanner 30 Sept 2024 2 33 PM
12 pages
Oops Notes Curated by Sameer Raza
PDF
No ratings yet
Oops Notes Curated by Sameer Raza
21 pages
Oop
PDF
No ratings yet
Oop
20 pages
Object Concepts and Terminology-2
PDF
No ratings yet
Object Concepts and Terminology-2
16 pages
Object-Oriented Programming With Java 7541-880
PDF
No ratings yet
Object-Oriented Programming With Java 7541-880
64 pages
Mactechgrp Artin CPP Casts
PDF
No ratings yet
Mactechgrp Artin CPP Casts
15 pages
C++ Succinctly - Casting in C++
PDF
No ratings yet
C++ Succinctly - Casting in C++
7 pages