How to Test Java programming skills Online Quiz 06

Explanations of answers for Quiz 06

Lesson Details:
January 14, 2020

This course is brought to you by Appy Pie as part of our Academy series hey they're here as chant once again and here as a yet another very simple but interesting program in here we have the main method and inside the main method we have a string variable the value of this string variable is steady easy and then moving forward in the next statement we are simply trying to print the index of small case II from the string now definitely there is a catch in this program if I execute this program the output would be minus 1 note that that whenever we make use of this index off method this will return the index of the first occurrence of the character which is passed to this method now this seems to be good enough but this method is also case sensitive as a result the small case II is not in the string and as a result the index of method will return minus 1 now note that whenever the index of method will not find the occurrence of the character in the string then the index of method will return minus 1 to the console so this was a very quick and easy to understand explanation hope you guys enjoyed it and I will catch you in the next video alright so here are a couple of more questions let us see what are these so the first question for this video is in the statement below what would be the effect on the string steady easy and the statement is pretty simple in here string STR equals the steady easy to replace Y with I now friends whenever we make use of replace method in here it will replace all the occurrence of that a specific value with the next value in here we would be replacing Y with I all right so in here if we check the steady easy string in here there are 2 i right so it would be steady easy alright ok so what are the options come violation error all characters wire would be replaced with I okay all characters I would be replaced with why no the first occurrence of wire is replaced with I know so the second option is the correct option and there is a note in here the replace method is a case sensitive method so if there are like smaller case and upper case letters in there so it would be specifically replaced the exact case letters with the exact other letter so in here why in a smaller case so both the Y and word study ez would be replaced and the final result would be steady easy but what the wire would be replaced with I so I suppose the explanation was good enough right so let's proceed further let us check the answer click on next and here is the next question the string class belongs to which package or right and I suppose there is no specific package as Java dot a string I suppose this is inside Java dot Lang right so let us check the answer oh my gosh I got this correct once again let's click on next and then moving forward the next question is what is the return type of constructor oh my gosh what is the return type of constructor so the answer is constructor never returns a value so the fourth option has the correct option constructor doesn't return any value not even white all right so this was very simple in fact all right let's check the answer once again God let's proceed further all right question number 5 the static method cannot be accessed directly from the class level true or false well the overall logic or the overall idea of a static method is to give a separate memory locations so that we can directly access them from the class level and the statement is false in fact because it says static method cannot be accessed directly from the last level well they can be accessed from the class level so we will say Falls for the statement let us check the answer good job hey then here is a yet another interesting program and in this program we have two variables first one as a a is int entity and the value of a is 55 then we have float B the value of B is fifty five point five now B is a float entity this is the reason why we need to explicitly specify F and in fact if I remove F then there would be an issue the alternative way of handling this situation is typecasting the number to float so both of the ways are good enough let me undo the changes alright so here is our original program and finally in the system dot out dot print statement we are simply making use of the modulus operator now the modulus operator is an interesting operator this operator will divide the left-hand side operand by the right-hand side operand and finally it will also return the remainder so a very interesting and in here we are simply dividing a with 10 so 55 would be divided by 10 the output would be 50 and the remainder would be 5 so we will get 5 as the output for this operation and then we will also perform a yet another operation on 55.5 and again we will divide 55.5 with 10 so the remainder would be 5.5 so let me show you the output and here is the output so pretty simple and easy to understand program but definitely the modulus operator is an interesting and useful operator in programming world thanks for watching and take care Jiri then here is a yet another program and the question is will this program execute properly without any compilation error and the answer is yes this program will execute properly and we won't be able to get any compilation error but if we check this program definitely there is some kind of error because a constructor cannot be static but the output is proper but how come the output and the constructor is not proper the reason is pretty simple the constructor would be only called when we create an object of this class and in this program we are not creating any object of this class for example if I quickly add in a new statement in here and for example I create a new object of this class then definitely there would be a compile time error and here is the compile time error so the answer to this question is yes this program will execute properly without any compilation error the current program where we are not creating any kind of object of the class but definitely you can't declare a static type constructor that's simply not possible all right so saying this this was a quick explanation of the question hope you enjoyed the explanation thanks for watching and I will catch you in the next video hey man here is the next question and the question is pretty simple the question is what would be Matt dot floor 6.6 pretty simple right so in here whenever we call the floor method it will simply ignore the decimal part of it so in here six point six in here after the decimal point there is six that value would be ignored as a result the final output would be 6.0 so the correct answer is 6.0 all right let me check the answer good job so here is the next question in which area of memory Java stores local variables whenever there is a method call now there is a tricky sentence formation in order to confuse you a little but don't confuse and that the question is pretty simple where Java stores the local variable pretty simple question now the answer is a stack and this is a theory sort of question and this is a good to know information so the correct answer is the second option stacked let me check the answer good job all right so let's check the last question from this quiz and the question is two or more methods with same name in the same class with the different arguments is called as definitely it has method overloading so the second option is the correct option good job so these were couple of questions with that explanation and I hope you guys enjoyed it thanks for watching and I will catch you in the next video with a new explanation.

loader
Course content