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. This code is only for send sms? can it also alert
View Tutorial          By: abdul kadir at 2009-10-23 05:37:46

2. This is a great idea if I am targeting the require
View Tutorial          By: Shanthamurthy Hanumantharayappa at 2015-09-14 16:45:22

3. good
View Tutorial          By: thamim at 2012-09-01 03:22:26

4. Thanks this article helped (just needed to know wh
View Tutorial          By: sushi at 2008-12-17 08:09:51

5. i want to know how to connect one page to another
View Tutorial          By: mahesh at 2009-08-26 01:31:40

6. Bad article ! What about the explanation of Messag
View Tutorial          By: Manish at 2011-05-24 04:44:03

7. When copying this code into my java IDE, should i
View Tutorial          By: Barabas at 2010-02-11 03:57:09

8. org.apache.jasper.JasperException: An exception oc
View Tutorial          By: manikanta at 2015-02-02 05:39:09

9. This article is not correct. Two-way synchronizat
View Tutorial          By: Travis at 2015-07-14 12:28:32

10. Thank ... for idea But
i m confuse how run

View Tutorial          By: Tanaji at 2010-06-01 23:13:19