How to Test Java programming skills Online Quiz 09

Explanations of answers for Quiz 09

Lesson Details:
January 14, 2020

This course is brought to you by Appy Pie as part of our Academy series hey there here is a yet another question in front of us and we need to determine the output for this program now this program is little tricky you can try to simulate what should be the output of this program but I can straight away tell you that there is a compile time error in this program because we are simply catching the exception first and then we are trying to catch the arithmetic exception as a result for this question definitely the answer is compile time error let me check the answer good job hey then here is a yet another program in front of us and in here we have a class by the name of quiz alright so this is good enough and then moving forward we also have the main method in here and inside the main method we have try catch and finally block as well so this time we are also checking out the finally block which is good alright so in here we are simply calling in the method acts first of all so let us quickly check the method X as well and inside the method X there is a exception thrown all right so we are simply throwing automatic exception all right so the exception is thrown as a result the next statement will not get executed and the exception would be caught by our automatic exception block as a result the statement inside the catch block will get executed all right and the statement is simply system dot out dot print B so alphabet B would be printed on the console first of all now moving forward we also have the finally block and inside the finally block we have a yet another statement the statement will print D so first of all we will print B then we will print D and outside the try catch and finally block we also have a yet another statement in here and this statement will simply print e so as it is the output should be B D e all right so this seems to be good enough let us check whether our program gives a proper output yes BD e was the expected output and our program is also giving the same output hey there here is yet another program in front of us and in here first of all we have a class by the name of quiz and inside this class quiz we have a static method method X all right so this is cool let us take a main method first inside the main method first of all we have a try block and inside the try block we are simply calling in the method X and there is a catch block as well and finally after the try catch block we also have a simple hello world statement good enough so now let us check the method X all right so first point in here method X is a static method as a result we can directly call this method alright so in here inside the method X we have the try finally block and the try block is parently throwing I exception now before returning the main method the finally block will get executed as a result first of all the finally text would be printed on our console the statement inside our finally block will get executed then moving forward the try block inside our main method is encountered with an exception as a result the catch block of the main method will get executed right so the catch block is highlighted right now you can view this on our screen moving forward inside this catch block we are simply printing the text exception so after the text finally if we would be printing exception and finally we will be also printing hello world so pretty simple finally exception hello world would be the output for this program let us check whether we have caught this right yes the output is perfect and the correct option is finally exception hello world alright so this was the explanation a quick explanation indeed thanks for watching and I catch you in the next video hey there there are a couple of more interesting question in front of us let us check in order to achieve object serialization under Java we need to implement serializable interface well the answer is true all right let us proceed further what is the next question lambda expression is available from which version of Java and I suppose the lambda expression was introduced after version 8 I suppose let me check the answer and I got that right let us proceed further now well wish number 6 try with resources are available from which version of Java I suppose this was available post version 7 of Java let me check the answer good job once again let us proceed further and check the yet another question try with resources could be used for handling exception automatically closing the resource automatically for implementing type safety none of about the second option is the correct option the overall purpose of try with resources is to close the resource automatically all right so let's check the answer good job let's proceed further offered reader class s thread-safe yes definitely it is a thread safe class true all right so the ninth question it is not possible to create user-defined exception under Java well it is possible so definitely this statement is false and it is surely 100% possible to create user-defined exception in Java so now here is the final question from the squares in front of us when the statements placed and the finally block gets executed what are the options if an exception occurs if a no exception occurs the statement placed under finally block will always get executed none of above the third option is the correct option if we place any statements in our finally block they will get executed no matter whether the exception occurs or not so the third option is the correct option let's check the answer good job once again.

Course content