The Random class never needs to be imported Scope involves the areas where the n
ID: 3802626 • Letter: T
Question
Explanation / Answer
Answers:
(1) F
You need to import the Random class.
(2) T
Scope means the area in which the name of vars and methods is known.
(3) T
The static method is called using the name of the class so it does not require an object to be created to call that method.
(4) T
main() is the method that is first called by JVM.
(5) F
You can use any method in an expression except those methods whose return type is void, such methods can't be used in expressions because expression means to operate on something and void means the method returns nothing so how to operate if nothing is returned..
(6) F
In a while loop, the body gets executed only if the condition is true because while is an entry controlled loop. This statement is true for do-while loop as its body is executed at least once because it is the exit controlled loop so first the body is executed, then check the condition and repeat the same thing if and till the condition remains true.
(7) F
void method returns nothing that's why void word is written.
(8) T
This is true because until we know what an object is and we still want to apply the methods the same way main() is used, we need to make them public static so that the method can be called by its class name and can be called outside of the class.
(9) T
The nextInt(index) method of the Random class can be used to get the random number between 0 to index-1.
(10) T
This is true because x++ is post increment and ++x is pre increment so ++x is always evaluated first before the expression is evaluated and x++ is always evaluated after the expression is evaluated. So, using 1 in place of other always gives different values.
Please comment if there is any query. Thank you. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.