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. Thanks for the above description, but pls let me k
View Tutorial          By: Amit Goyal at 2009-09-25 05:33:10

2. Nice Article, but these concepts are pretty confus
View Tutorial          By: Goldest at 2011-03-18 01:50:50

3. can you provide the full class from start to begin
View Tutorial          By: mohit at 2011-12-01 09:56:22

4. Session Bean = client data is maintained upto pred
View Tutorial          By: Chetankumar at 2012-05-19 11:12:17

5. Very well explained and perfectly summarised.
View Tutorial          By: Sachin at 2009-08-30 12:39:27

6. wow , really good java sample , and i suggest to s
View Tutorial          By: kiemtheng at 2011-08-31 13:31:32

7. thanks for suppporting us
View Tutorial          By: sonia at 2010-11-29 00:46:56

8. Hello, your post helped me a lot with solving my o
View Tutorial          By: Florian Brunner at 2008-06-26 08:59:42

9. Doesn't the getline() on line 14 read "once u
View Tutorial          By: poo at 2011-02-22 00:32:44

10. Very good post.^^
View Tutorial          By: LAM at 2009-10-25 04:18:38