Comment on Tutorial - Type Casting in Java By Saravanan



Comment Added by : siddhant

Comment Added at : 2014-10-11 13:19:25

Comment on Tutorial : Type Casting in Java By Saravanan
Design program with given algorithm---

step1:Declare a variable x of type integer and assign it to the value 10
Step 2: Declare a variable y of type double and assign it the value of x.
Step 3: Print the value of y it will show no error it’s called implicit casting.
Step 4: Now, Set the value of y to 13.5
Step 5: Assign value of y to the x. (It raises compilation error because implicit casting doesn’t work as explained.)
Step 6: Use explicit casting (narrowing conversion) to assign y to x.
Step 7: print value of x (it gives you round off value y).
Step 8: Define a class named vehicle as a parent class, define a subclass of vehicle as car.
Step 9: create an object x of class vehicle.
Step 10: create an object y of class car.
Step 11: assign y to x (Its upcasting so no compilation error and no explicit casting is required)
Step 12: assign x to y (Its downcasting so it will give u compilation error. So use explicit casting)


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Hai.. i tried with d above code but am getting an
View Tutorial          By: muthupandi at 2010-08-17 09:49:23

2. If i delete a record, will that recId be replaced
View Tutorial          By: faisal at 2009-06-08 21:36:29

3. Good and Simple Example For Beginners Like me.Than
View Tutorial          By: Lasantha Bandara at 2010-06-29 19:21:48

4. Thanks a lot for this great post.
View Tutorial          By: Ram Para at 2012-03-23 17:07:09

5. how to read any xml file or i want to a universal
View Tutorial          By: shankar lal at 2014-09-29 12:40:20

6. good one !
View Tutorial          By: qasim at 2008-05-18 03:16:55

7. where i put this rar file to include comm api
View Tutorial          By: shubham bansal at 2015-02-20 12:13:16

8. estimado lo que sucede es que solo cuando es Strin
View Tutorial          By: hormiga at 2013-01-07 00:11:54

9. i have using struts tag in jsp ,
i have us

View Tutorial          By: sachin khatode at 2008-11-11 01:24:33

10. Thanks..
Short & Sweet Description.

View Tutorial          By: Prashaad at 2012-02-23 17:37:14