How to Test Java programming skills Online Quiz 03

Explanations of answers for Quiz 03

Lesson Details:
January 14, 2020

This course is brought to you by Appy Pie as part of our Academy series alright so the next question is in Java or array is options are primitive data type object reference object no no follow definitely the correct option is object but a complex object in an array that could be multiple entities in an array for example a array of integer will contain array of integer variable right but it is definitely object so let me check the answer and the next question is which one of the following is a valid statement let me check and the first option is a valid declaration here the first option is a valid declaration where we are giving the size of an array giving the size of error is important and minded and this is one of the way how we can likely declare a care array well rest of these options are not correct let me check the option called John hey there here is a yet another program and we need to determine the output for the same now this program is pretty simple and if if we execute this program the output would be one and now we will check why exactly the output is one first of all inside the main method we have two variables these variables are a and B the value of a is set as 15 and the value of B is set as 26 now where is the catch inside this program and the catch is definitely inside this if statement now if we check this if statement inside this if a statement first of all we have these brackets right and inside this bracket we have a operation as we already know that first of all the bracket operation would be done so definitely B equals to zero operation would be performed first and as a result the value of B would be converted to zero which is good enough moving forward we will be checking whether zero is equals to a in the answer is false right the value of a is 15 and the current value of B is zero so B equals two equals to zero no that's a false a statement as a result the else block of if statement would be get executed and if we check the system dot out dot println a statement in here we are prefixing plus plus two B so first of all the value of B would be increased to 1 and then we will definitely display the value of B the current value of B is zero and after the increase of 1 2 the value of B are definitely the output would be 1 so this is all about today's program and the output is pretty simple the correct option is 1 thanks for watching and I will catch you in the next one hey then here is a yet another program and we need to determine the output for the same in here we have a class by the name of quiz then we have a main method and inside the main method we have couple of statements now this program is pretty simple first of all we have a variable X the value initialized to X as 5 and if we check the system dot out dot println statement inside this statement we are performing operation and this operation is of a relational type as a result this operation will give us either true or false as the value of x is also 5 definitely this operation will give us true and definitely the output for the program is true so this was a very simple program indeed and the correct option is true thanks for watching and I will catch you in the next one hey there welcome back and here is a yet another program in this program we have a class by the name of quiz and there is a main method and there are a couple of operations right and we need to determine what is the output for the same the value of a is true right value of B is a not true this means the value of B is false then we are performing operation so C equals to a and B now the value of a true the value of B is false so true and false will give us yes false so value of C is again false and if we check the value of D then it is a or B value of a is true value of B as false and the operator in between is R as a result the value of D will become true all right so the rule of RS if either of the operands are true then the output will be true likewise if we check the rule for and if either of the operands are false then the output will be false so the value of C is false the value of T is true now we are simply displaying the value of C first so the C is false and then we are also displaying the value of D so the value of D is true so the final output should be false true all right so let me show you the output and here as the output false true so the correct option is false true and that's it for this program hope you guys enjoyed the explanation thanks for watching and I will catch you in the next one alright so moving ahead when we pass an array to a method the method receives a good question what are the options the reference of an array code a copy of the first element a copy of the array well it is not the correct option either the first option is the correct option always remember this the reference of the array is received by the method and using the reference we can definitely access the elements in the array alright so this seems to be good enough let me like the option you click on check answer good job hey then here is a yet another question and we need to determine the output for the same in here first of all we have the class by the name of quiz inside the class we have the main method now inside the main method first of all we have initialize the variable X where to value one which is fairly straightforward now if we check the do-while loop this do-while loop is based on this variable X and the number of iteration based on this variable X would be 3 because inside this while loop the condition is X less than equal to 3 so there is one thing which is straightforward that there would be 3 iteration for this loop all right moving forward in here in first line inside the loop we have statement into y equal to 2 and here is the catch of friends now in here this variable Y would be initialized and declared in every iteration yes and this means that a separate copy of this variable would be created in every iteration and as soon as the iteration will get completed this local variable veritime alright so in every iteration the value of a wire would remain - all right so that is good enough moving forward the last statement inside this do my loop is simply displaying the value of y now firstly we are displaying the value of a Y and then we are increasing the value of Y by 1 definitely once the iteration is over the local copy of Y will die and a new copy of Y will get created in the memory so this wire plus plus will have no effect on the output of the program and in every iteration the output from this line number 8 would be only 2 so let me show you what is the output of this program and it is pretty simple the output would be 2 2 and 2 alright so this was a quick explanation for this program I hope I have made myself clear thanks for watching and take care hey then here is I get another program and we need to determine the output no friends this program seems to be very simple but there is again a catch in here first of all we have a class by the name of quiz and inside the main method we have a do-while loop and inside the Dubai loop we are simply printing the message hello world which is good enough and inside this condition we are printing true this means infinite loop now this program seems to be a infinite loop but when we try to execute this program that would be a syntax error and it will throw an error at line number 6 the reason is pretty simple in do-while loop we need to add semicolon after the while statement now this is a silly mistake made by many of us I suppose and we need to always remember that after the while condition we need to include the semicolon then only our program shall work and now if we execute this program definitely this is an infinite loop all right let me terminate this program and that this is all about to this lecture I hope and I suppose the explanation was good enough I will catch you in the next video all right so the next question as a do-while loop is useful when we point the statements within the loop must be executed at least once this is a common sort of question which might be asked by you multiple times because a do-while loop has a unique property that even the condition has false the statements inside the loop would be executed at least once and the correct option is the second option what are the options given once at least once more than once till the condition in a loop is true definitely the second option is the correct option let's check the next question the next question is a statement continue jump statement can skip processing remaining statements in the loop body for a particular iteration true or false it is definitely true and in fact this statement is nothing but the overall definition of continuous statement the purpose of continuous statement is to skip processing the remaining statement when the continuous statement occur inside the loop so definitely the statement is true and let us check the answer good job.

loader
Course content