How to Test Java programming skills Online Quiz 08

Explanations of answers for Quiz 08

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 program in front of us and let us check what would be the output for the same in here we have a class by the name of quiz and inside this class we have the main method and we have to intervene evil and these variable are true and false the value of truest and value of false as zero right and we are simply trying to apply the end operation on these two int entity and it is pretty simple the end operation could be performed on the boolean type of entity as a result there would be an error and if we try to execute this program that would be a compile time error so the correct answer for this question is the output of this program would be a compile time error hope you guys got the point by that is a compile time error and if there is any confusion a research mode on and operator all right so this is it for this video this is chan signing off hey there here is a yet another question the name of the class is quiz once again and there is a main method and inside the main method there is a switch case right and the first statement inside the main method is initialization of variable x and y the value of x is one value of y is 2 alright so if we add both of these two variable then the value the combined value could be 3 so the switch case is on value 3 as a result case 3 will get executed and the value of y would be initialized to 0 which is good enough but note that in here we are not making use of any break statements right and inside the switch case no break as there is no break the next case will also get executed right so the key is 5 as y equal to 1 right so now the value of Bayeux would be of moving forward the default case will also get executed and the cases y+ equals to five and that this would be equivalent to y equals to y plus five what is the current value of y the current value of y as 1/1 plus 5s 6 so the value of y of would be 6 by the end of the switch case and finally we would be printing the value of y so let us execute this program and check whether this works properly or not and here is the output so this has simply a good example and a good question thanks for watching in the correct option as six hey there here is I get another question and the question is which of the following loop will be an infinite loop so the first loop 4 semicolon semicolon is an infinite loop correct for I equals to 1 is greater than 0 I plus plus alright so this is again a infinite loop because the condition won't be false anytime he around we are simply increasing the value of I then there is for I equals to 0 the condition part is missing I minus minus so this is also an infinite loop so finally the correct option is all off above all the 3 of these loops are infinite loop let me check the answer good job hey then here is a yet another program and let us check what will be the output for this program the name of the class of squares and inside the main method first of all we have a into variable the name of the variable as X and the value of this variable is 10 and then we have a while loop and finally after the while loop we are simply printing the value of x now what is the value of x value of x is 10 now if we check the by loop it is X plus plus is less than equals to 10 first of all we will check the comparison access less than equal to 10 the condition is true then we will also increase the value of X and that the value of x will become 11 then inside the loop once again we will increase the value of x by 1 so the value of x will become 12 in the next iteration again we will check x plus plus is a less than equal to 10 the condition is false but the value of x will be increased by a bun and the condition would be false as a result then we will be finally printing the value of x let us check whether the value of x would be 13 or not I guess you guys are getting it in first iteration the value of x will reach 12 and the next iteration where we would be checking out the condition whether X is less than equal to 10 or not the condition of X would be 12 but after checking the condition the value of x will be increased by 1 once again so the final value of x should be 13 so here is the final answer and I suppose the explanation was good enough and if there is some confusion do try to play with these loops and try to research on how the plus plus operator works that will surely help you guys to understand these kind of question all right so this is it for today's lecture and I will catch you in the next video with a new explanation hey there here are a couple of more interesting questions the first question in this video is what is the superclass of all exceptional type classes let me check and the credit option is through able now friends this is a theory short off question and there is no specific explanation to this always remember that superclass of all exceptional type class is definitely throw able let me check good job let's proceed further and check the next question so here is the next question which handler handles the exception when no catch is used let me repeat this once again which handler handles the exception when no catch is used and if we check these options these options are Java Runtime system throw handler finally the correct option is default handler let me check the answer good job let's proceed further the next question is which operator is used to generate an instance of an exception now what is the exception exception is also a type auth object as a result the new keyword would be used let me check the answer good job let's proceed further which keyword from options below is not a part of exception handling let us check try is a part of exception handling finally is part of exception handling through is not in fact and catch is also part of exception handling so the correct answer is true let me check answer good job alright so these were quick explanation of four questions I hope you guys got the point why the correct options are the correct options hope you guys enjoyed the video thanks for watching and I will catch you in the next video with a new question and a new explanation hey there here is a yet another program the name of the class is quiz once again there is a main method and then finally we have a try-catch block alright so this seems to be good enough alright so inside this try block the first statement is int I equals 2 minus 1 and sum equals 200 so there are two variable I equals 2 minus 1 and sum equals 200 all right then there is a while loop and the condition inside the while loop is true as a result this is an infinite while loop all right so the first statement inside this while loop is sum equals to sum divided by I so we are simply dividing 100 by minus 1 which is perfect and then we are simply printing the value of I the correct value of I as minus 1 so minus 1 would be printed on the console then moving forward we would be in using the value of i buy one as a result of value of one will become zero alright in the next iteration we will again perform the operation sum equals to some divided by I and here as the catch there would be a automatic exception as a result the catch block will catch the exception and inside the catch block there is a statement and the statement is system dot out dot println and we are simply printing zero as a result the final output for this program would be minus ten let me show you the output and here is the output all right so this was again an interesting program and the correct option for this question is minus ten hope you guys enjoyed the lecture and I will catch you with a new explanation in the next video hey there welcome back and here is a yet another program in front of us and this program is again a pretty simple program there is a class by the name of quiz and inside the main method we have couple of statements let us check these statements one by one and x equals to five y equals to zero all right and then that is a trial block alright so the value of y is zero there is a catch in here right so inside this system dot out dot print statement we are simply printing hello and then there is a operation in here in the operation as X divided by Y the value of a Y is zero as a result that would be a automatic exception and the catch block will catch our exception now in here there is a exception inside this a statement as a result this statement will not print hello right and the output would be simply world instead of hello world alright so let me show you the output here we go so what is a catch in here if there is an exception in any statement then that statement will not execute partially the statement will simply skip and the catch block will catch your exception as a result the hello keyword will not get printed on the console and output would be simply world I hope you guys understood the point all right so this was a quick explanation and I will catch you in the next video with a new explanation.

Course content