More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. Yes. Methods invoked from within a finally block can throw an exception. Failure to catch and handle such exceptions results in the abrupt termination of the entire try block.
Help us improve. Please let us know the company, where you were asked this question :
Ans. AssertionError is actually a fatal fault or a bug in the program. We may not like to continue program , request or thread execution if this error occurs as this condition is the assumption to continue further execution.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Its a type of ArrayList in which all Write operations , i.e add and set are performed by creating a new copy. This array never changes during the lifetime of the iterator, so it never throws ConcurrentModificationException
Help us improve. Please let us know the company, where you were asked this question :
Ans. This collections class has been implemented in such a manner that it can never throw ConcurrentModificationException. As it performs update and write operations by creating a new copy of ArrayList, It's slower compared to ArrayList.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Exception thrown by the application is we try to access an element using an index which is not within the range of array i.e lower than 0 or greater than the size of the array.
Help us improve. Please let us know the company, where you were asked this question :
Though the following code will compile fine but will result in ClassCastException during runtime.
Fruit fruit = new Apple();
Banana banana = Banana(fruit); // ClassCastException
This code will not give compile time error as Banana and Fruit are related as Banana either extends or implement Fruit, So downcasting is acceptable. With this code we assume that the Fruit handler will have the Apple object at that point, violating which the code will throw the exception.
This exception can be avoided by following code.
Fruit fruit = new Apple();
if(fruit instanceOf Banana){
Banana banana = Banana(fruit); // ClassCastException
}
Help us improve. Please let us know the company, where you were asked this question :
a. try block followed by catch b. try block followed by finally c. try block followed by catch block and then finally d. try block without catch or finally block
Ans. try block without catch or finally block
Help us improve. Please let us know the company, where you were asked this question :
Ans. Fail Safe systems are tolerant systems that continue processing even if they sense any problem. the objective here is to continue with the processing even if there are some problems instead of completely shutting it down. Example could be to catch an exception and still letting it complete with partial results.
Help us improve. Please let us know the company, where you were asked this question :
Ans. <a href="http://www.programcreek.com/2009/02/diagram-for-hierarchy-of-exception-classes/" rel="nofollow">http://www.programcreek.com/2009/02/diagram-for-hierarchy-of-exception-classes/</a>
Help us improve. Please let us know the company, where you were asked this question :
Q51. Can we have try statement without catch? If try statement contains return will the finally block be executed? What happens if there is an exception inside finally block?
Ans. NumberFormatException is the exception that Java throws when we try to convert one data type to the Number data type but the value is not parsable to be a Number.
For example , the following code will result in the NumberFormatException
String string = "Buggy";
int strtoInt = Integer.parseInt(string);
Help us improve. Please let us know the company, where you were asked this question :
Ans. In first case the whole loop will terminate as soon as any exception happens in the method calculate ( assuming calculate method is not handling its exception and those are thrown back at the calling method )
In Second case exception will be caught for individual iteration and hence it wont break the loop and will continue for the next iteration.
Help us improve. Please let us know the company, where you were asked this question :