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
- Data Science
- React Native
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Read a file having a list of telnet commands and execute them one by one using Java
Open a .docx file and show content in a TextArea using Java
Step by Step guide to setup freetts for Java
Of Object, equals (), == and hashCode ()
Using the AWS SDK for Java in Eclipse
DateFormat sample program in Java
concurrent.Flow instead of Observable class in Java
Calculator application in Java
Sending Email from Java application (using gmail)