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. Hello Nishi,
The class names in your progra

View Tutorial          By: Kiran at 2011-12-16 06:32:54

2. thanks man!u r lifesaver!!!!!!!
View Tutorial          By: sneha at 2009-03-17 23:56:40

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

4. thank you
i memorized it easly .

View Tutorial          By: kibrom at 2011-04-27 11:46:24

5. Question, how much is Struts 2 used today? As a fr
View Tutorial          By: Marco at 2012-10-04 06:34:43

6. The code to show recursion is ok, but the declara
View Tutorial          By: Gaurav at 2010-08-08 01:08:27

7. I agree with #2 u are missing that line
View Tutorial          By: ויזה לארה"ב at 2011-10-26 10:39:50

8. Good article
View Tutorial          By: Manu Francis Mathew at 2009-12-18 00:50:45

9. Hi,
I need to put in a picturebox on VB .NE

View Tutorial          By: Marcio Rodrigues at 2009-11-27 05:07:09

10. pls send me the brief description about jdbc conne
View Tutorial          By: vikas at 2011-08-09 07:07:53