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



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. I am certifed java Business Component Developer, m
View Tutorial          By: Kobs at 2013-02-26 11:58:22

2. how to read csv file using Java
View Tutorial          By: Shireesha at 2013-12-26 07:34:22

3. hai
i can run this program bt 1 exception

View Tutorial          By: Raheela at 2010-05-25 21:59:38

4. Thanks for the above code. I am not sure whether t
View Tutorial          By: Koolkabin at 2010-08-20 01:11:27

5. Hi all this program is working very fine .... i ha
View Tutorial          By: Ashish at 2009-03-25 04:28:25

6. insert a value in excel is not a problem but inser
View Tutorial          By: durga at 2010-03-05 23:08:02

7. Hello all,

I need the codes for sen

View Tutorial          By: Fionna at 2009-07-13 00:34:45

8. You do not give an example on fillratio i want to
View Tutorial          By: reguieg at 2015-08-23 20:53:50

9. I am using my NOKIA 2700 via blutooth connection.
View Tutorial          By: Rahi at 2010-05-11 04:39:33

10. I will not contest. Certainly this is extremely im
View Tutorial          By: Bangabee at 2012-11-10 18:17:40