Monday, July 18, 2016

Is this variable declaration is valid?

       
In the below different variable declaration is valid.

Class Test{


  1.         int a=0.0;  
  2. Integer b=23.4;
  3. String s='d';
  4. char c="sample";
  5. char ch[]="simple data";
  6. float f=34.5;
  7. double d=f;
  8. long l=d;

}

1.Compilation error. Error : Type mismatch: cannot convert from double to int
2.Compilation error: Error:  Type mismatch: cannot convert from double to Integer
3.Compilation error: Error:  Type mismatch: cannot convert from char to String
4.Compilation error: Error:  Type mismatch: cannot convert from String to char
5.Compilation error: Error:  Type mismatch: cannot convert from String to Char Array
6.Compilation error: Error:  Type mismatch: cannot convert from double to float
8.Compilation error: Error:  Type mismatch: cannot convert from double to long

No comments:

Post a Comment