6. What will happen if you call return statement or System.exit() on try or catch block ? will finally block execute?
Answer is that finally block will execute even if you put return statement in try block or catch block but finally block won't run if you call System.exit() form try or catch.
7. What is method hiding?
To create a method with same return type and same method arguments similar to private or static method is known as method hiding.
8. Can we use String in the switch case?
Yes from Java 7 onward it is possible to use String in switch case but it is just syntactic visual. Actually a string hash code is used for the switch.
Yes from Java 7 onward it is possible to use String in switch case but it is just syntactic visual. Actually a string hash code is used for the switch.
9. Difference between x = x + y and x += y ?
The += operator implicitly casts the result of addition into the type of variable is supposed to hold the result.
Sample Code:
byte x = 127;
byte y = 127;
x = x + y; // error : cannot convert from int to byte
x += y; // ok
10. What will this return 5*0.1 == 0.5? true or false?
The condition will be return as false because some floating point numbers can have problem for exact representation.
No comments:
Post a Comment