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



Ask a Question

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. Hi Ramalak,
My modem is connected to COM3 p

View Tutorial          By: divya at 2008-04-30 23:19:26

2. OK 0
COM1
javax.comm.CommPortIdenti

View Tutorial          By: sruthi at 2013-01-20 10:37:41

3. nice tutorial
View Tutorial          By: Rakesh at 2012-05-30 01:13:00

4. Thanks for the digital shell clock: very cool, and
View Tutorial          By: Lol loller at 2012-04-11 15:40:45

5. good article that help us
View Tutorial          By: D.md.Rafi at 2013-04-28 02:30:18

6. Exception in thread "main" java.lang.NoC
View Tutorial          By: Lahrach Abdelhakim at 2015-02-18 14:38:03

7. What is AWS?
View Tutorial          By: Toja at 2013-01-22 10:36:45

8. Does your Siemens CX75 can show up as COM port dev
View Tutorial          By: mchon at 2008-10-10 18:24:11

9. Hey this code is very helpful......can you please
View Tutorial          By: Preetam Purbia at 2010-03-01 04:25:47

10. When I use this code it puts everything I append o
View Tutorial          By: Amber at 2012-06-18 15:33:22