Java MCQ-2023 - SET 3
Java MCQ-2023 - SET 3
Java MCQ
Revision Test-3
(1) Which of the following are valid comments?
(i) /* comment */
(ii) /* comment
(iii) // comment
(iv) */ comment */
a) (i) & (iii)
b) (i) & (ii)
c) All of the above
d) None of the above
(2) Arrange the operators given below in order of higher precedence to lower precedence.
(i) && (ii) % (iii) >= (iv) ++
a) (iv), (i), (iii), (ii)
b) (iv), (iii), (ii), (i)
c) (iv), (ii), (iii), (i)
d) (i), (ii), (iii), (iv)
(3) Which of the following keyword is used to create an instance of a class?
a) new
b) public
c) class
d) None of the above
(4) What is the final value stored in variable x ?
double a = -8.35;
double x = Math.abs(Math.floor(a));
a) 9.0
b) 7.0
c) 6
d) 7
(5) Name the type of error in the statement given below:
int r=100/0;
a) Syntax
b) Runtime
c) Logical
d) None of the above
(6) The _____________ allows a class to use the properties and methods of another class.
a) Inheritance
b) Polymorphism
c) Encapsulation
d) None of the above
(7) The number of bytes occupied by char data type is __________byte/s
a) 4
b) 8
c) 2
d) None
(8) The _________ is called an instance of a class
a) object
b) Attributes
c) State
d) None
(9) The ____________ are the words which have special meaning
a) Keywords
b) Identifier
c) Methods
d) Package
(10) Method that accepts a string without any space is _______
a) next()
b) nextLine()
c) nextInt()
d) nextSpace()
(11) The keyword to make a variable as a class variable
a) Static
b) Static
c) Final
d) new
(12) Intermediate code obtained after compilation
a) Source code
b) Byte Code
c) Object code
d) JVM
(13) The method with the same name as of the class and which does not have a return data type is
called as
a) Constructor
b) Function
c) Method
d) Data member
(14) The statement to stop the execution of a construct.
a) System.exit(0)
b) break
c) STOP
d) continue
(15) Invoking a method by passing the objects of a class is termed as
a) Call by value
b) call by reference
c) call by method
d) call by program
(16) Choose the odd one
a) Encapsulation
b) Data abstraction
c) Portable
d) Polymorphism
(17) Choose the odd one
a) >
b) ==
c) &&
d) <
(18) Choose the odd one
a) return
b) break
c) continue
d) System.exit(0)
(19) Choose the odd one
a) int
b) double
c) char
d) String
(20) Choose the odd one
a. +
b. %
c. /
d. ||
(21) Give the output of the following
x + = x++ + ++ x + --x + x; when x = 5
a. 29
b. 28
c. 26
d. 27
(22) Give the output of the following
if ( a > b )
System.out.println(a+b);
System.out.println (a*b); when a = 5 and b = 7
a) 12, 35
b) 35
c) 35, 12
d) no output
(23) String x = (a >= 90) ? "excellent" : "best"; when a = 90
a) best
b) excellent
c) excellentbest
d) 90
(24) Give the output of the following when x='A'
switch ( x )
{ case 'a' : System.out.println("Discipline");
case 'b' : System.out.println ("Dedication"); break;
case 'c' : System.out.println("Commitment");
default : System.out.println("Success");
}
a. Discipline
b. Dedication
c. Success
d. Discipline Dedication
(25) How many time the loop is executed and what is the output?
n=1000;
while (n>10)
{ n=n/10;
}
System.out.println(n);
a) Loop is executed 2 times and the output is 100
b) Loop is executed 3 times and the output is 10
c) Loop is executed 2 times and the output is 10.
d) Loop is executed 4 times and the output is 0
(26) When primitive data type is converted to its corresponding object of its class, it is called as
___________.
a) Boxing
b) Explicit type conversion
c) Unboxing
d) Implicit type conversion
(27) State the value of y after the following is executed:
char x='7';
y= Character.isLetter(x);
a) false
b) 7
c) true
d) ‘7’
(28) Give the output of the following string methods:
"MISSISSIPPI".indexOf('S')+ "MISSISSIPPI".lastIndexOf('I')
a) 10
b) 12
c) 20
d) 11
(29) Corresponding wrapper class of int data type is __________.
a) integer
b) INTEGER
c) Int
d) Integer
(30) Variable that is declared within the body of a method is termed as:
a) Instance variable
b) class variable
c) Local variable
d) Argument variable
(31) Identify the correct array declaration statement:
a) int a[10];
b) int a[]=new int[10];
c) int arr[i]=10;
d) int a[10]=new int[];
(32) A variable that is bounded to the object itself is called as:
a) Instance variable
b) class variable
c) Local variable
d) Argument variable
(33) The access modifier that gives least accessibility is:
a) private
b) public
c) protected
d) default
(34) Give the output of the following code:
String A ="26.0", B="74.0";
double C= Double .parseDouble(A);
double D = Double .parseDouble(B);
System.out.println((C+D));
a) 26
b) 74
c) 100.0
d) 2674
(35) Wrapper classes are available in __________ package.
a) java.io
b) java.util
c) java.lang
d) java.awt.
(36) Wrapping up of data and methods together as one unit is termed as:
a) Inheritance
b) Polymorphism
c) Encapsulation
d) Abstraction
(37) The data type which is specified that the method does not return a value is:
(a) Void
(b) void
(c) VOID
(d) Boolean
(38) The logical operator which is a unary operator:
(a) &&
(b) ||
(c) !
(d) ++
(39) The Scanner class is a ________ class.
(a) Primitive
(b) Derived
(c) Wrapper
(d) Super class
(40) Math.pow(625, ½ ) + Math.sqrt(144)
(a) 17.0
(b) 13.0
(c) 37.0
(d) 13
(41) The correct if statement for the following ternary operation statement is:
System.out.println(n % 2 == 0? “true”;”false”;);
(a) if(n % 2 == 0)
return true;
else
return false;
(b) if(n % 2 == 0)
return “true”;
else
return “false”;
(c) if(n % 2 == 0)
System.out.println(“true”);
else
System.out.println(“false”);
(d) if(n % 2 == 0)
System.out.println(true);
else
System.out.println(false);
(42) Multiple branching statement of Java is:
(a) For
(b) while
(c) do while
(d) switch
(43) The number of bytes occupied by the constant 45 are:
(a) Four bytes
(b) Two bytes
(c) Eight bytes
(d) One byte
(44) do while loop is an:
(a) Entry-controlled loop
(b) Infinite loop
(c) Exit-controlled loop
(d) Finite loop
(45) How many times the inner loop is executed?
for(k = 1; k <= 2; k++)
{
for(m = 1; m <= 4; m++)
{
System.out.println(m * 2);
}
}
(a) 4 times
(b) 8 times
(c) 2 times
(d) 16 times
(46) A method with the same name as of the class and with arguments and
(a) parameterized constructor
(b) default constructor
(c) non-parameterized constructor
(d) wrapper class method
(47) int res = ‘A’; What is the value of res?
(a) A
(b) 66
(c) 65
(d) 97
(48) The style of expressing single line comment is:
(a) /* comment */
(b) * comment
(c) //comment
(d) /* comment
(49) The method to check if a character is an alphabet or not is:
(a) isLetter(char)
(b) isAlpha(char)
(c) isUpperCase(char)
(d) isLowerCase(char)
(50) The output of Double.parseDouble(“71.25”)+)+0.75 is:
(a) 72
(b) 72.0
(c) 71.0
(d) 71.75
(51) The method to convert a string to uppercase is:
(a) toUpperCase(char)
(b) toUPPERCASE(String)
(c) toUpperCase(String)
(d) touppercase(String)
(52) The output of the method “DETERMINATION".substring(2, 6) is:
(a) “TERM”
(b) “ETERM”
(c) “ETER”
(d) “TERMI”
(53) The array int x[10] occupies:
(a) 10 bytes
(b) 40 bytes
(c) 20 bytes
(d) 80 bytes
(54) The element in x[4] of the array {3, 5, 7, 12, 16, 18, 20, 35, 42, 89} is:
(a) 16
(b) 12
(c) 7
(d) 18
(55) Name the type of error that occurs for the following statement:
System.out.println(Math.sqrt(24-25));
(a) Syntax error
(b) Run-time error
(c) Logical error
(d) No error