java_mcq
java_mcq
14. A computer program that translates a high-level language program into machine code is:
A. Linker
B. Assembler
C. Library
D. Compiler
16. A computer program that translates an assembly language program into machine code is:
A. Linker
B. Assembler
C. Library
D. Compiler
2. Which character set would you use if you have characters from Hindi, Japanese and German
to display?
A) ASCII Character Set C) Unicorn Character Set
B) Extended ASCII Character Set D) Unicode Character Set
11. Which of the following is the size of short data type in Java?
A) 8 bits C) 24 bits
B) 16 bits D) 32 bits
12. Which of the following is the size of char data type in Java?
A) 8 bits C) 24 bits
B) 16 bits D) 64 bits
15. The keyword that converts a variable with its value into a constant is:
A) const C) constant
B) fixed D) final
22. Arrange the following primitive data types in the ascending order of
size: char, byte, double, int
A) byte, char, int, double
B) char, byte, int, double
C) byte, char, double, int
D) char, byte, int, double
4. Statement i = i -1 is equivalent to
A) i--
B) --i
C) i -= 1
D) All of the above
6. Given num1 = 0, num2 = 1 the statement (num1 < num2) && (num1 > num2) evaluates to
A) true
B) false
C) 1
D) 0
7. Given num1 = 0, num2 = 1 the statement (num1 < num2) || (num1 > num2) evaluates to
A) true
B) false
C) 1
D) 0
8. Given num1 = 0, num2 = 1 the statement !(num1 > num2) evaluates to
A) true
B) false
C) 1
D) 0
E)
15. What is the result stored in x, after evaluating the following expression?
int x = 5;
x = x++ * 2 + 3 * --x;
A) 25
B) 24
C) 23
D) 26
16. What will be the result stored in X after evaluating the following expression?
int X = 4;
X += (X++) + (++X) + X;
A) 19
B) 20
C) 21
D) 22
A) 70 A
B) 71 A
C) A70
D) 72 A
A) m=65
B) m=97
C) m=’a’
D) m=’A’
A) 3
B) 4
C) 5
D) 6
21. An operator taking three operands for its operation is:
A. A unary operator
B. A binary operator
C. A ternary operator
A. 2
B. 12
C. 0
D. 48
A. 65
A. A
B. null
C. c
Part 4 - Inputs in Java
A) 1 only
B) 3 only
C) 1 and 3
D) 1, 3 and 4
2. Name the type of error that occurs for the following statement:
System.out.println(Math.sqrt(36-45));
A) Syntax error
B) Runtime error
C) Logical error
D) No error
3. Name the type of error that occurs for the following statement:
int a;b;c;
A) Syntax error
B) Runtime error
C) Logical error
D) No error
4. Pick the statement that will include all the classes present in java.util package into your program:
A) include java.util
B) java.util
C) package java.util
D) import java.util
5. Name the type of error that occurs for the following scenario:
Division by a variable that contains a value zero.
A) Syntax error
B) Runtime error
C) Logical error
D) No error
6. Name the type of error that occurs for the following scenario:
Multiplication operator used when the operation should be division.
A) Syntax error
B) Runtime error
C) Logical error
D) No error
7. Name the type of error that occurs for the following scenario:
Missing semicolon at the end of a statement.
A) Syntax error
B) Runtime error
C) Logical error
D) No error
10. Which of the following statement we must write to import just the Scanner class from
the java.util package
A) import java.util.*
B) import package java.util.Scanner
C) include java.util.Scanner
D) import java.util.Scanner
A) 2 only
B) 4 only
C) 2 and 4
D) 2, 3 and 4
12. Name the method of Scanner class that is used to input an integer data from the standard
input device
A) NextInt()
B) nextInteger()
C) nextNumber()
D) nextInt()
14. Name the input source that a Scanner object uses to accept data from the standard input device
A) System.in
B) System.input
C) Scanner.in
D) Java.input
A) Syntax error
B) Runtime error
C) Logical error
D) No error
16. Pick the invalid method that is not in the Scanner class:
A) nextInt()
B) next()
C) nextNumber()
D) nextLong()
18. The pacakage that contains methods to display date and time is:
A) Java.date
B) Java.lang
C) Java.io
D) Java.util
19. Which statement is true?
A) The next() method is used to read the next complete token
B) The nextLine() method is used to read a complete line of text
C) The next().charAt(0) returns the first character
D) All of the above
20. Name the method of Scanner class that checks if the Scanner has another token in its input:
A) hasNext()
B) nextToken()
C) getNext()
D) hasNextToken()
A) 8.0
B) 7.0
C) -7.0
D) -8.0
A) 9.0
B) 10.0
C) 11.0
D) 12.0
A) -9.0
B) -10.0
C) 9.0
D) 10.0
A) -2.84
B) -6.54
C) 2.84
D) 6.54
5. What is the output of the following Math function?
Math.sqrt(Math.floor(25.9))
A) 25.0
B) 5.0
C) 26.0
D) 6.0
Math.ceil(4.5 + 4.4)
A) 8.0
B) 9.0
C) 10.0
D) Runtime error
A) 1
B) -1
C) 0
D) Runtime error
14. Which of the following is a method to find the cube root of a number?
A) cubeRoot(x)
B) Cbrt(x)
C) Math.cubeRoot(x)
D) Math.cbrt(x)
int x = 1, y = 1;
if (n > 0)
{
x++;
--y;
}
What will be the value of x and y when n = 0?
A) x = 2, y = 0
B) x = 0, y = 2
C) x = 1, y = 0
D) x = 1, y = 1
int x = 1, y = 1;
if (n > 0)
{
x++;
--y;
}
A) x = 2, y = 0
B) x = 0, y = 2
C) x = 1, y = 0
D) x = 1, y = 1
if (x = y);
x=0
else
x++
String grade = (marks >= 90) ? "A": (marks > 80) ? "B" : "C";
A) A
B) B
C) C
D) Runtime error
int p = 3, q = 2, r = 1;
switch(n)
{
case 1: p++;
case 2: q++;
case 3: r++;
}
A) p = 3, q = 3, r = 2
B) p = 3, q = 3, r = 3
C) p = 3, q = 2, r = 2
D) p = 3, q = 2, r = 1
int p = 3, q = 2, r = 1;
switch(n)
{
case 1: p++;
case 2: q++;
case 3: r++;
}
A) p = 3, q = 3, r = 2
B) p = 3, q = 3, r = 3
C) p = 3, q = 2, r = 2
D) p = 3, q = 2, r = 1
12. Which statement will produce the absolute value of variable x?
A) x = x < 0 ? -x : -x;
B) x = x < 0 ? x : -x;
C) x = x > 0 ? -x : x;
D) x = x < 0 ? -x : x;
15. if ((a < b) && (a < c)), then which of the following statement is true?
A) a is the smallest number
B) b is the smallest number
C) c is the smallest number
D) b is the largest number
A) 4
B) 5
C) 6
D) Infinite time
2. How many times the following loop will
execute? int counter = 1;
do
{
System.out.println(counter);
}
while (counter++ < 5);
A) 4
B) 5
C) 6
D) Infinite time
A) 1
B) 2
C) 5
D) 6
A) 0
B) 1
C) 5
D) Infinite time
A) x = 6, y = 14
B) x = 6, y = 11
C) x = 5, y = 11
D) x = 5, y = 14
6. Given the following code
snippet: int j = 1, k = 2;
while (++k <
5) j *= k;
A) 6
B) 25
C) 36
D) 49
A) 1
B) 3
C) 9
D) 10
13. Which of the following for loops will cause the body of the loop to be executed 5 times?
A) for (int i = 5; i > 1; i-- )
B) for (int i = 1; i < 5; i++ )
C) for (int i = 0; i < 5; i++ )
D) for (int i = 0; i <= 5; i++ )