Java MULTIPLE CHOICE. Choose the one alternative that best completes the stateme
ID: 3802991 • Letter: J
Question
Java
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question
1) Which of the following statement prints smithexam1 est.txt? 1) A) System.out.println("smith"exam1" est.txt"); B) System.out.println("smithexam1 est.txt"); C) System.out.println("smith\exam1\test.txt"); D) System.out.println("smith"exam1"test.txt");
2) An int variable can hold ________. (Choose all that apply.) 2) A) 120 B) 120.0 C) "x" D) "120" E) 'x'
3) Suppose x is 1. What is x after x-= 1? 3) A) 0 B) 1 C) 2 D) -1 E) -2
4) What is y displayed in the following code?
public class Test { public static void main(String[ ] args) { int x= 1; int y= x+++ x; System.out.println("y is "+ y); } }
4)
A) y is 1. B) y is 4. C) y is 2. D) y is 3.
5) According to Java naming convention, which of the following names can be variables? (Choose all that apply.)
5)
A) findArea B) TOTAL_LENGTH C) FindArea D) totalLength E) class
1
6) What is y displayed in the following code?
public class Test1 { public static void main(String[ ] args) { int x= 1; int y= x= x + 1; System.out.println("y is "+ y); } }
6)
A) y is 2 because x + 1 is assigned to x and then x is assigned to y. B) y is 1 because x is assigned to y first. C) y is 0. D) The program has a compile error since x is redeclared in the statement int y= x = x+ 1.
7) What is the printout of System.out.println('z'- 'a')? 7) A) z B) a C) 25 D) 26
Explanation / Answer
4th Question :
4) What is y displayed in the following code?
public class Test { public static void main(String[ ] args) { int x= 1; int y= x+++ x; System.out.println("y is "+ y); } }
4)
A) y is 1. B) y is 4. C) y is 2. D) y is 3.
Answer :
D) y is 3.
Description :
The location of the shortcut operator is only important if the operator is used in an expression where the operand value is assigned to another variable or returned from a method.
Operator Use description
++ x++ y = x++; is the same as y = x; x = x + 1;
++x y = ++x; is the same as x = x + 1; y = x;
6) What is y displayed in the following code?
public class Test1 { public static void main(String[ ] args) { int x= 1; int y= x= x + 1; System.out.println("y is "+ y); } }
Answer : y is 2
Description : In first step : value of x is 1,
second step : added 1 in x and assigned to value in y then print out value of y.
1) Which of the following statement prints smithexam1 est.txt? 1) A) System.out.println("smith"exam1" est.txt"); B) System.out.println("smithexam1 est.txt"); C) System.out.println("smith\exam1\test.txt"); D) System.out.println("smith"exam1"test.txt");
Answer : System.out.println("smith\exam1\test.txt");
Description : the backslashes are doubled due to being in Java string literals - so the actual strings involved here are "single backslash" and "double backslash" - not double and quadruple.
7) What is the printout of System.out.println('z'- 'a')? 7) A) z B) a C) 25 D) 26
Answer : C) 25
In above code : Decimal value of z char is : 90 and Decimal value of a char is 65
System.out.println(90 - 65) : 25
In java, some decimal value of all char like as a to z.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.