Statistics
The Highest Post







Statistics
Count 94
Avg 21.00
Min 21
Max 21
Angualr Top questions

Details



Peter Agyekum What is the difference between an implicit conversion and an explicit conversion? 1. Explicit conversions require a cast operator whereas an implicit conversion is done automatically. <br> 2. Explicit conversion can lead to data loss whereas with implicit conversions there is no data loss. <br> What type of data type conversion happens when the compiler encounters the following code?ChildClass CC = new ChildClass(); <br> ParentClass PC = new ParentClass(); <br><br> Implicit Conversion. For reference types, an implicit conversion always exists from a class to any one of its direct or indirect base classes or interfaces. No special syntax is necessary because a derived class always contains all the members of a base class. <br><br> Will the following code compile? <br> double d = 9999.11;<br> int i = d;<br><br> No, the above code will not compile. Double is a larger data type than an integer. An implicit conversion is not done automatically bcos there is a data loss. Hence we have to use explicit conversion as shown below. <br><br> double d = 9999.11;<br> int i = (int)d; //Cast double to int.<br>
Related Topics