if you can understand next few lines you won't have problem in anything related to casting.
Casting means what ? Caasting an object of Type A into Type B. A is what --?some class definition. So is B. means A has some attributes and some operations supported so is B. When u want to cast A into B, then all the operations and attributes of B should be suported by A as well. (and this has to be forced. You should not or compiler can't allow any aberation it has to know or be sure that yes A can be casted into B. If A now extends B. Means A is of Type B. so here if you want to use type B in place of Type A, no explicit casting is required. coz its forced, that A has to and supports all of B's attributes and functions. because A extends B. is is of type B. but opposite is not true. At least its not forced, that B supports all attributes and functions suported by A. an least its not forced anyway. Emmanuel Eze wrote: >can u give an example of explicit cast? > >-----Original Message----- >From: RAMESH VISHNUVARDHAN [mailto:[EMAIL PROTECTED]] >Sent: Tuesday, May 07, 2002 12:18 PM >To: JDJList >Subject: [jdjlist] RE: [jdjlist] casting > > > >When you assign a variable of parent class type to an object of subclass, >the implicit casting occurs. >Example: >java.util.Date parentDate = null; >parentDate = new java.sql.Date(Calendar.getInstance().getTime().getTime()); >The above code is valid. Here we no need to do explicit casting >. >Regards, >Vishnu > > >-----Original Message----- >From: Emmanuel Eze >To: JDJList >Sent: 5/7/02 11:08 AM >Subject: [jdjlist] casting >This cast thing is beginning to get me confused. if I cannot cast a >java.util.Date to a java.sql.Date since the util.Date is the ancestor >class, >can I cast a java.sql.Date to java.util.Date. I really wish to >understand >the nitty gritty of casting. > > > > > >To change your membership options, refer to: >http://www.sys-con.com/java/list.cfm > > >To change your membership options, refer to: >http://www.sys-con.com/java/list.cfm > > To change your membership options, refer to: http://www.sys-con.com/java/list.cfm
