Oops MCQ Answers
Oops MCQ Answers
Introduction to java
MCQ No - 1
D
MCQ No - 2
C
MCQ No - 3
With x = 0, which of the following are legal lines of Java code for changing the value of x to
1?
1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;
(A) 1, 2 & 3
(B) 1 & 4
(C) 1, 2, 3 & 4
(D) 3 & 2
C
JAYA COLLEGE OF ENGG & TECHNOLOGY
DEPARTMENT COMPUTER SCIENCE AND ENGINEERING
MCQ No - 4
A
MCQ No - 5
MCQ No - 6
}
}
(A) 1 1
(B) 0 1
(C) 1.5 1
(D) 1.5 1.0
C
MCQ No - 7
(A) 5.640000000000001 5
(B) 5.640000000000001 5.0
(C) 5 5
(D) 5 5.640000000000001
A
MCQ No - 8
(A) 25
(B) 24
(C) 32
(D) 33
C
MCQ No - 9
Can 8 byte long data type be automatically type cast to 4 byte float data type?
(A) True
(B) False
A
MCQ No - 10
(A) 3 2 4
(B) 3 2 3
(C) 2 3 4
(D) 3 4 4
MCQ No - 11
Which of these is not a bitwise operator?
(A) &
(B) &=
(C) |=
(D) <=
D
MCQ No - 12
Which operator is used to invert all the digits in a binary representation of a number?
(A) ~
(B) <<<
(C) >>>
(D) ^
A
MCQ No - 13
On applying Left shift operator, <<, on integer bits are lost one they are shifted past which
position bit?
(A) 1
(B) 32
(C) 33
(D) 31
D
MCQ No - 14
B
MCQ No - 15
MCQ No - 16
(A) 42 42
(B) 43 43
(C) 42 -43
(D) 42 43
C
MCQ No - 17
(A) 7 2
(B) 7 7
(C) 7 5
(D) 5 2
A
MCQ No - 18
(A) 0 64
(B) 64 0
(C) 0 256
(D) 256 0
D
MCQ No - 19
(A) 10
(B) 5
(C) 2
(D) 20
B
MCQ No - 20
(A) 3 1 6
(B) 2 2 3
(C) 2 3 4
(D) 3 3 6
MCQ No - 21
B
MCQ No - 22
Which of these is returned by “greater than”, “less than” and “equal to” operators?
(A) Integers
(B) Floating – point numbers
(C) Boolean
(D) None of the mentioned
C
MCQ No - 23
(A) 3 & 2
(B) 1 & 4
(C) 1, 2 & 4
(D) 1, 2 & 3
D
MCQ No - 24
D
MCQ No - 25
Which of these statements is correct?
(A) true and false are numeric values 1 and 0
(B) true and false are numeric values 0 and 1
(C) true is any non zero value and false is 0
(D) true and false are non numeric values
MCQ No - 26
(A) 1
(B) 0
(C) True
(D) False
D
MCQ No - 27
D
MCQ No - 28
(A) 0
(B) 1
(C) 3
(D) -4
C
MCQ No - 29
(A) 1
(B) 2
(C) Runtime error owing to division by zero in if condition
(D) Unpredictable behavior of program
B
MCQ No - 30
(A) 0
(B) 1
(C) false
(D) true
MCQ No - 31
A
MCQ No - 32
(A) Integer
(B) Floating – point numbers
(C) Boolean
(D) None of the mentioned
C
MCQ No - 33
(A) 0
(B) 1
(C) 9
(D) 8
D
MCQ No - 34
MCQ No - 36
(A) 10
(B) 11
(C) 12
(D) 56
C
MCQ No - 37
(A) 24 8
(B) 24 9
(C) 27 8
(D) 27 9
D
MCQ No - 38
}
}
D
MCQ No - 39
C
MCQ No - 40
MCQ No - 41
A
MCQ No - 42
Which concept of Java is a way of converting real world objects in terms of class?
(A) Polymorphism
(B) Encapsulation
(C) Abstraction
(D) Inheritance
C
MCQ No - 43
Which concept of Java is achieved by combining methods and attribute into a class?
(A) Encapsulation
(B) Inheritance
(C) Polymorphism
(D) Abstraction
A
MCQ No - 44
B
MCQ No - 45
Which component is responsible for converting bytecode into machine specific code?
(A) JVM
(B) JDK
(C) JIT
(D) JRE
MCQ No - 46
D
MCQ No - 47
C
MCQ No - 48
A
MCQ No - 49
C
MCQ No - 50
MCQ No - 51
A
MCQ No - 52
B
MCQ No - 53
A
MCQ No - 54
(A) 1 and 2
(B) 2 and 3
(C) 3 and 4
(D) All statements are correct
D
MCQ No - 55
An expression involving byte, int, and literal numbers is promoted to which of these?
(A) int
(B) long
(C) byte
(D) float
MCQ No - 56
B
MCQ No - 57
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
(A) Infinity
(B) 0.0
(C) NaN
(D) all of the mentioned
D
MCQ No - 58
D
MCQ No - 59
Which of these coding types is used for data type characters in Java?
(A) ASCII
(B) ISO-LATIN-1
(C) UNICODE
(D) None of the mentioned
C
MCQ No - 60
MCQ No - 61
C
MCQ No - 62
What will be the output of the following Java program?
class mainclass {
public static void main(String args[])
{
char a = 'A';
a++;
System.out.print((int)a);
}
}
(A) 66
(B) 67
(C) 65
(D) 64
A
MCQ No - 63
(A) 162
(B) 65 97
(C) 67 95
(D) 66 98
B
MCQ No - 64
A
MCQ No - 65
MCQ No - 66
B
MCQ No - 67
D
MCQ No - 68
D
MCQ No - 69
B
MCQ No - 70
MCQ No - 71
If an expression contains double, int, float, long, then the whole expression will be promoted
into which of these data types?
(A) long
(B) int
(C) double
(D) float
C
MCQ No - 72
(A) E U
(B) U E
(C) V E
(D) U F
A
MCQ No - 73
B
MCQ No - 74
How many primitive data types are there in Java?
(A) 6
(B) 7
(C) 8
(D) 9
C
MCQ No - 75
MCQ No - 76
Which one of these lists contains only Java programming language keywords?
(A) class, if, void, long, Int, continue
(B) goto, instanceof, native, finally, default, throws
(C) try, virtual, throw, final, volatile, transient
(D) strictfp, constant, super, implements, do
B
MCQ No - 77
B
MCQ No - 78
A
MCQ No - 79
A
MCQ No - 80
(A) true
(B) false
(C) Compilation fails
(D) An exception is thrown at runtime
MCQ No - 81
What will be the output of the program?
class Test
{
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";
System.out.println(sup);
}
}
(A) small
(B) tiny
(C) huge
(D) Compilation fails
B
MCQ No - 82
(A) 5 3
(B) 8 2
(C) 8 3
(D) 8 5
B
MCQ No - 83
(A) 0
(B) 7
(C) 8
(D) 14
D
MCQ No - 84
A
MCQ No - 85
MCQ No - 86
(A) 50
(B) 10
(C) Compilation Error
(D) None of these
C
MCQ No - 87
(A) 2
(B) 0
(C) 3
(D) 2.5
B
MCQ No - 88
(A) 2
(B) 129
(C) -127
(D) Compiler error
C
MCQ No - 89
{
System.out.println("block");
}
public A(){
System.out.println("A");
}
B
MCQ No - 90
int x = 0, y = 0 , z = 0 ;
x = (++x + y-- ) * z++;
MCQ No - 91
(A) 12
(B) 11
(C) 10
(D) 23
C
MCQ No - 92
Select from among the following character escape code which is not available in Java.
(A) \t
(B) \r
(C) \a
(D) \\
C
MCQ No - 93
(A) TRUE
(B) FALSE
(C) Compiler Error
(D) None of these
A
MCQ No - 94
C
MCQ No - 95
Determine output:
public class Test{
static int i = 5;
public static void main(String... args){
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
System.out.println(++i+i++);
}
}
(A) 6 6 6 16
(B) 6 7 6 16
(C) 5 6 7 16
(D) 5 6 6 16
MCQ No - 1
C
MCQ No - 2
What is the valid data type for variable “a” to print “Hello World”?
switch(a)
{
System.out.println("Hello World");
}
D
MCQ No - 3
D
MCQ No - 4
B
MCQ No - 5
D
MCQ No - 6
A
MCQ No - 7
switch(x)
{
default:
System.out.println("Hello");
}
(A) 1 and 3
(B) 2 and 4
(C) 3 and 5
(D) 4 and 6
A
MCQ No - 8
public void test(int x)
{
int odd = 1;
if(odd)
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
A
MCQ No - 9
public class While
{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x + 1)); /* Line 8 */
}
}
}
D
MCQ No - 10
Determine output:
public class Test{
public static void main(String args[]){
int i;
for (i=1;i<6;i++){
if(i>3) contine;
}
System.out.println(i);
}
}
(A) 2
(B) 3
(C) 4
(D) 6
MCQ No - 11
In java, ............ can only test for equality, where as .......... can evaluate any type of the
Boolean expression.
(A) switch, if
(B) if, switch
(C) if, break
(D) continue, if
A
MCQ No - 12
D
MCQ No - 13
Determine output:
public class Test{
public static void main(String args[]){
int i;
for(i = 1; i < 6; i++){
if(i > 3) continue ;
}
System.out.println(i);
}
}
(A) 2
(B) 3
(C) 4
(D) 6
D
MCQ No - 14
A
MCQ No - 15
Determine output:
public class Test{
public static void main(String args[]){
int i, j;
for(i=1, j=0;i<10;i++) j += i;
System.out.println(i);
}
}
(A) 10
(B) 11
(C) 9
(D) 20
MCQ No - 16
(A) 1
(B) 2
(C) 3
(D) 4
B
MCQ No - 17
What is the printout of the following switch statement?
char ch = 'a';
switch (ch){
case 'a':
case 'A': System.out.print(ch); break;
case 'b':
case 'B': System.out.print(ch); break;
case 'c':
case 'C': System.out.print(ch); break;
case 'd':
case 'D': System.out.print(ch);
}
(A) abcd
(B) aa
(C) a
(D) ab
C
MCQ No - 18
How many times will the following code print "Welcome to DIET"?
int count = 0;
do {
System.out.println("Welcome to DIET");
count++;
} while (count < 10);
(A) 8
(B) 9
(C) 10
(D) 11
C
MCQ No - 19
(A) 1 2 3 1
(B) 1 2 3 2
(C) Repeatedly print 1 2 3 and cause infinite loop.
(D) Compilation fails because of line 2
C
MCQ No - 20
What all gets printed when the following program is compiled and run.
public class Test{
public static void main(String args[]){
int i, j=1;
i = (j>1)?2:1;
switch(i){
case 0: System.out.println(0); break;
case 1: System.out.println(1);
case 2: System.out.println(2); break;
case 3: System.out.println(3); break;
}
}
}
(A) 0
(B) 1
(C) 2
(D) 1 2
MCQ No - 21
What will be the output?
public class Test{
public static void main(String args[]){
int i = 1;
do{
i--;
}while(i > 2);
System.out.println(i);
}
}
(A) 1
(B) 2
(C) -1
(D) 0
D
MCQ No - 22
(A) 10
(B) 11
(C) 12
(D) 13
D
MCQ No - 23
What will be the result of compiling and runnig the following code:
public class Test{
public static void main(String... args) throws Exception{
Integer i = 34;
int l = 34;
if(i.equals(l)){
System.out.println("true");
}else{
System.out.println("false");
}
}
}
(A) true
(B) false
(C) Compiler error
(D) None of these
A
MCQ No - 24
1. public class Test{
2. public static void main(String [] args){
3. int x = 0;
4. // insert code here
5. do{ } while(x++ < y);
6. System.out.println(x);
7. }
8. }
C
MCQ No - 25
MCQ No - 26
A
MCQ No - 27
B
MCQ No - 28
What would be the output of the following code snippet if variable a=10?
if(a<=0)
{
if(a==0)
{
System.out.println("1 ");
}
else
{
System.out.println("2 ");
}
}
System.out.println("3 ");
(A) 1 2
(B) 2 3
(C) 1 3
(D) 3
D
MCQ No - 29
(A) 5 10
(B) 10 5
(C) 5
(D) 10
D
MCQ No - 30
(A) Hello
(B) run time error
(C) Hello world
(D) compile time error
MCQ No - 31
C
MCQ No - 32
(A) 5
(B) 6
(C) 14
(D) compilation error
B
MCQ No - 33
(A) 1
(B) 2
(C) 3
(D) 4
B
MCQ No - 34
B
MCQ No - 35
Which of these jump statements can skip processing the remainder of the code in its body for
a particular iteration?
(A) break
(B) return
(C) exit
(D) continue
MCQ No - 36
Which of the following loops will execute the body of loop even when condition controlling
the loop is initially false?
(A) do-while
(B) while
(C) for
(D) none of the mentioned
A
MCQ No - 37
A
MCQ No - 38
MCQ No - 1
B
MCQ No - 2
D
MCQ No - 3
}
}
(A) 16.34
(B) 16.566666644
(C) 16.46666666666667
(D) 16.46666666666666
C
MCQ No - 4
(A) i i i i i
(B) 0 1 2 3 4
(C) i j k l m
(D) None of the mentioned
A
MCQ No - 5
(A) 38
(B) 39
(C) 40
(D) 41
MCQ No - 6
}
}
(A) 0 2 4 6 8
(B) 1 2 3 4 5
(C) 0 1 2 3 4 5 6 7 8 9
(D) 1 2 3 4 5 6 7 8 9 10
B
MCQ No - 7
What will be the output of the following Java program, if we run as “java main_arguments 1
2 3”?
class main_arguments
{
public static void main(String [] args)
{
String [][] argument = new String[2][2];
int x;
argument[0] = args;
x = argument[0].length;
for (int y = 0; y < x; y++)
System.out.print(" " + argument[0][y]);
}
}
(A) 1 1
(B) 1 0
(C) 1 0 3
(D) 1 2 3
D
MCQ No - 8
Which will legally declare, construct, and initialize an array?
(A) int [] myList = {"1", "2", "3"};
(B) int [] myList = (5, 8, 2);
(C) int myList [] [] = {4,9,7,0};
(D) int myList [] = {4, 3, 7};
D
MCQ No - 9
(A) 1, 2, 4
(B) 2, 4, 5
(C) 2, 3, 4
(D) All are correct.
A
MCQ No - 10
Which one of the following will declare an array and initialize it with five numbers?
(A) Array a = new Array(5);
(B) int [] a = {23,22,21,20,19};
(C) int a [] = new int[5];
(D) int [5] array;
MCQ No - 11
(A) int
(B) byte
(C) long
(D) double
D
MCQ No - 13
A
MCQ No - 14
(A) 2, 4
(B) 3, 5
(C) 4, 5
(D) 1, 2
D
MCQ No - 15
void start()
{
boolean b1 = false;
boolean b2 = fix(b1);
System.out.println(b1 + " " + b2);
}
MCQ No - 16
(A) 0
(B) value stored in arr[0]
(C) 00000
(D) Class name@ hashcode in hexadecimal form
D
MCQ No - 18
A
MCQ No - 19
A
MCQ No - 20
(A) 0 2 4 6 8
(B) 1 3 5 7 9
(C) 0 1 2 3 4 5 6 7 8 9
(D) 1 2 3 4 5 6 7 8 9 10
MCQ No - 21
(A) 11
(B) 10
(C) 13
(D) 14
B
MCQ No - 22
(A) 3
(B) 0
(C) 6
(D) 1
D
MCQ No - 23
D
MCQ No - 24
(A) 8
(B) 9
(C) 10
(D) 11
B
MCQ No - 25
What is the type of variable ‘b’ and ‘d’ in the following Java snippet?
int a[], b;
int []c, d;
C
MCQ No - 26
(A) ArrayIndexOutOfBoundsException
(B) ArrayStoreException
(C) Compilation Error
(D) Code runs successfully
B
MCQ No - 27
D
MCQ No - 28
B
MCQ No - 29
MCQ No - 31
A
MCQ No - 32
A
MCQ No - 33
A
MCQ No - 34
Which one of the following is a valid statement?
(A) char[] c = new char();
(B) char[] c = new char[5];
(C) char[] c = new char(4);
(D) char[] c = new char[];
B
MCQ No - 35
(A) 0
(B) Compilation error, arrays cannot be initialized to zero size.
(C) Compilation error, it is a.length() not a.length
(D) None of the above
MCQ No - 36
(A) The program has a compile error because the size of the array wasn't specified when
declaring the array.
(B) The program has a runtime error because the array elements are not initialized.
(C) The program runs fine and displays x[0] is 0.
(D) The program has a runtime error because the array element x[0] is not defined.
C
MCQ No - 37
(A) 0
(B) 1
(C) 2
(D) 3
B
MCQ No - 38
Determine output:
public class Test{
public static void main(String[] args){
int[] x = {1, 2, 3, 4};
int[] y = x;
x = new int[2];
C
MCQ No - 39
(A) The code has compile errors because the variable arr cannot be changed once it is
assigned.
(B) The code has runtime errors because the variable arr cannot be changed once it is
assigned.
(C) The code can compile and run fine. The second line assigns a new array to arr.
(D) The code has compile errors because we cannot assign a different size array to arr.
C
MCQ No - 40
MCQ No - 41
When you pass an array to a method, the method receives ________ .
(A) A copy of the array.
(B) A copy of the first element.
(C) The reference of the array.
(D) The length of the array.
C
MCQ No - 42
D
MCQ No - 43
(A) 0
(B) 1
(C) 2
(D) 3
B
MCQ No - 44
Choose all the lines which if inserted independently instead of "//insert code here" will allow
the following code to compile:
public class Test{
public static void main(String args[]){
add();
add(1);
add(1, 2);
}
MCQ No - 1
What is the stored in the object obj in following lines of Java code?
box obj;
B
MCQ No - 2
A
MCQ No - 3
A
MCQ No - 4
C
MCQ No - 5
Which keyword is used by the method to refer to the object that invoked it?
(A) import
(B) catch
(C) abstract
(D) this
MCQ No - 6
D
MCQ No - 7
B
MCQ No - 8
Which of these keywords is used to prevent content of a variable from being modified?
(A) final
(B) last
(C) constant
(D) static
A
MCQ No - 9
A
MCQ No - 10
MCQ No - 11
Which of the following is a method having same name as that of its class?
(A) finalize
(B) delete
(C) class
(D) constructor
D
MCQ No - 12
Which operator is used by Java run time implementations to free the memory of an object
when it is no longer needed?
(A) delete
(B) free
(C) new
(D) none of the mentioned
D
MCQ No - 13
Which function is used to perform some action when the object is to be destroyed?
(A) finalize()
(B) delete()
(C) main()
(D) none of the mentioned
A
MCQ No - 14
C
MCQ No - 15
MCQ No - 16
B
MCQ No - 17
B
MCQ No - 18
B
MCQ No - 19
D
MCQ No - 20
MCQ No - 21
D
MCQ No - 22
B
MCQ No - 23
D
MCQ No - 24
A
MCQ No - 25
Determine output:
public class Test{
int i = 34;
public static void main(String args[]){
Test t1 = new Test();
Test t2 = new Test();
t1.i = 65;
System.out.print(t1.i);
System.out.print(t2.i);
}
}
(A) 34 34
(B) 65 34
(C) 65 65
(D) 34 65
MCQ No - 26
What is the output for the below code ?
class A{
int k;
boolean istrue;
static int p;
public void printValue(){
System.out.print(k);
System.out.print(istrue);
System.out.print(p);
}
}
(A) 0 false 0
(B) 0 true 0
(C) 0 0 0
(D) Compile error - static variable must be initialized before use.
A
MCQ No - 27
Determine output:
public class Test{
int a = 10;
B
MCQ No - 28
(A) Compile error at line 1 (static x must be only accessed inside static methods)
(B) Compile error at line 3 (static methods can't make reference to non-static variables)
(C) Compile error at line 4 (invalid argument type for method main)
(D) 49
B
MCQ No - 29
void call(){
this.a++;
System.out.print(this.a);
}
}
A
MCQ No - 30
(A) 9
(B) 8
(C) Compilation error
(D) Runtime error
MCQ No - 31
What will be the output of the following Java program?
class box
{
int width;
int height;
int length;
}
class mainclass
{
public static void main(String args[])
{
box obj1 = new box();
box obj2 = new box();
obj1.height = 1;
obj1.length = 2;
obj1.width = 1;
obj2 = obj1;
System.out.println(obj2.height);
}
}
(A) 1
(B) 2
(C) Runtime error
(D) Garbage value
A
MCQ No - 32
(A) 0
(B) 1
(C) Runtime error
(D) classname@hashcode in hexadecimal form
D
MCQ No - 33
}
class Output
{
public static void main(String args[])
{
area obj = new area();
obj.area(5 , 6);
System.out.println(obj.length + "" "" + obj.width);
}
}
(A) 0 0
(B) 5 6
(C) 6 5
(D) 5 5
C
MCQ No - 34
(A) 1 2
(B) 2 3
(C) 3 2
(D) 1 5
D
MCQ No - 35
What will be the output of the following Java program?
class access
{
static int x;
void increment()
{
x++;
}
}
class static_use
{
public static void main(String args[])
{
access obj1 = new access();
access obj2 = new access();
obj1.x = 0;
obj1.increment();
obj2.increment();
System.out.println(obj1.x + "" "" + obj2.x);
}
}
(A) 1 2
(B) 1 1
(C) 2 2
(D) Compilation Error
MCQ No - 36
(A) 7 7
(B) 6 6
(C) 7 9
(D) 9 7
MCQ No - 1
A
MCQ No - 2
Which of this keyword can be used in a subclass to call the constructor of superclass?
(A) super
(B) this
(C) extent
(D) extends
A
MCQ No - 3
What is the process of defining a method in a subclass having same name & type signature
as a method in its superclass?
(A) Method overloading
(B) Method overriding
(C) Method hiding
(D) None of the mentioned
B
MCQ No - 4
D
MCQ No - 5
MCQ No - 6
C
MCQ No - 7
D
MCQ No - 8
C
MCQ No - 9
B
MCQ No - 10
MCQ No - 11
D
MCQ No - 12
B
MCQ No - 13
C
MCQ No - 14
A
MCQ No - 15
You want subclasses in any package to have access to members of a superclass. Which is the
most restrictive access that accomplishes this objective?
(A) public
(B) private
(C) protected
(D) transient
MCQ No - 16
What is the most restrictive access modifier that will allow members of one class to have
access to members of another class in the same package?
(A) public
(B) abstract
(C) protected
(D) default access
D
MCQ No - 17
Given a method in a protected class, what access modifier do you use to restrict access to
that method to only the other members of the same class?
(A) final
(B) static
(C) private
(D) protected
C
MCQ No - 18
B
MCQ No - 19
Which of these is not abstract?
(A) Thread
(B) AbstractList
(C) List
(D) None of the Mentioned
A
MCQ No - 20
If a class inheriting an abstract class does not define all of its function then it will be known
as?
(A) Abstract
(B) A simple class
(C) Static class
(D) None of the mentioned
MCQ No - 21
C
MCQ No - 22
A
MCQ No - 23
In order to restrict a variable of a class from inheriting to subclass, how variable should be
declared?
(A) Protected
(B) Private
(C) Public
(D) Static
B
MCQ No - 24
If super class and subclass have same variable name, which keyword should be used to use
super class?
(A) super
(B) this
(C) upper
(D) classname
A
MCQ No - 25
MCQ No - 26
Which of these class is used to create an object whose character sequence is mutable?
(A) String()
(B) StringBuffer()
(C) String() & StringBuffer()
(D) None of the mentioned
B
MCQ No - 27
Which of this method of class StringBuffer is used to concatenate the string representation
to the end of invoking string?
(A) concat()
(B) append()
(C) join()
(D) concatenate()
B
MCQ No - 28
Which of these method of class StringBuffer is used to find the length of current character
sequence?
(A) length()
(B) Length()
(C) capacity()
(D) Capacity()
A
MCQ No - 29
(A) Hell
(B) ello
(C) Hel
(D) llo
B
MCQ No - 30
MCQ No - 31
D
MCQ No - 32
B
MCQ No - 33
Which of these operators can be used to concatenate two or more String objects?
(A) +
(B) +=
(C) &
(D) ||
A
MCQ No - 34
Which of these method of class String is used to extract a single character from a String
object?
(A) CHARAT()
(B) chatat()
(C) charAt()
(D) ChatAt()
C
MCQ No - 35
Which of these constructors is used to create an empty String object?
(A) String()
(B) String(void)
(C) String(0)
(D) None of the mentioned
MCQ No - 36
C
MCQ No - 37
Which of these method of class String is used to compare two String objects for their
equality?
(A) equals()
(B) Equals()
(C) isequal()
(D) Isequal()
A
MCQ No - 38
Which of these methods is used to compare a specific region inside a string with another
specific region in another string?
(A) regionMatch()
(B) match()
(C) RegionMatches()
(D) regionMatches()
D
MCQ No - 39
Which of these methods of class String is used to check whether a given object starts with a
particular string literal?
(A) startsWith()
(B) endsWith()
(C) Starts()
(D) ends()
A
MCQ No - 40
What is the value returned by function compareTo() if the invoking string is less than the
string compared?
(A) zero
(B) value less than zero
(C) value greater than zero
(D) none of the mentioned
MCQ No - 41
Which of these data type value is returned by equals() method of String class?
(A) char
(B) int
(C) boolean
(D) all of the mentioned
C
MCQ No - 42
Which of these method of class String is used to remove leading and trailing whitespaces?
(A) startsWith()
(B) trim()
(C) Trim()
(D) doTrim()
B
MCQ No - 43
What is the value returned by function compareTo() if the invoking string is greater than the
string compared?
(A) zero
(B) value less than zero
(C) value greater than zero
(D) none of the mentioned
C
MCQ No - 44
At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers among
“final, static, native, public, private, abstract, protected”
1. public interface Status
2. {
3. /* insert qualifier here */ int MY_VALUE = 10;
4. }
D
MCQ No - 45
(A) 2 2
(B) 3 3
(C) Runtime Error
(D) Compilation Error
MCQ No - 46
(A) 1
(B) 2
(C) 3
(D) 4
B
MCQ No - 47
C
MCQ No - 48
(A) 2 2
(B) 3 3
(C) 2 3
(D) 3 2
C
MCQ No - 49
What will be the output of the following Java program?
class A
{
public int i;
public int j;
A()
{
i = 1;
j = 2;
}
}
class B extends A
{
int a;
B()
{
super();
}
}
class super_use
{
public static void main(String args[])
{
B obj = new B();
System.out.println(obj.i + " " + obj.j)
}
}
(A) 1 2
(B) 2 1
(C) Runtime Error
(D) Compilation Error
A
MCQ No - 50
(A) 2 2
(B) 3 3
(C) Runtime Error
(D) Compilation Error
MCQ No - 51
D
MCQ No - 52
(A) Hello
(B) World
(C) Helloworld
(D) Hello World
D
MCQ No - 53
C
MCQ No - 54
(A) xello
(B) xxxxx
(C) Hxllo
(D) Hexlo
C
MCQ No - 55
(A) HelloGoodWorld
(B) HellGoodoWorld
(C) HellGood oWorld
(D) Hello Good World
MCQ No - 56
(A) a
(B) b
(C) c
(D) abc
D
MCQ No - 57
(A) TRUE
(B) FALSE
(C) 0
(D) 1
B
MCQ No - 58
C
MCQ No - 59
In the following Java code, which code fragment should be inserted at line 3 so that the
output will be: “123abc 123abc”?
1. StringBuilder sb1 = new StringBuilder("123");
2. String s1 = "123";
3. // insert code here
4. System.out.println(sb1 + " " + s1);
D
MCQ No - 60
What will be the output of the following Java code?
class output
{
public static void main(String args[])
{
String chars[] = {"a", "b", "c", "a", "c"};
for (int i = 0; i < chars.length; ++i)
for (int j = i + 1; j < chars.length; ++j)
if(chars[i].compareTo(chars[j]) == 0)
System.out.print(chars[j]);
}
}
(A) ab
(B) bc
(C) ca
(D) ac
MCQ No - 61
C
MCQ No - 62
What will be the output of the following Java program?
class output
{
public static void main(String args[])
{
String s1 = "Hello";
String s2 = s1.replace('l','w');
System.out.println(s2);
}
}
(A) hello
(B) helwo
(C) hewlo
(D) hewwo
D
MCQ No - 63
(A) Hell
(B) Hello
(C) Worl
(D) World
A
MCQ No - 64
}
}
(A) 4 8
(B) 5 9
(C) 4 9
(D) 5 8
A
MCQ No - 2
C
MCQ No - 3
A
MCQ No - 4
Which of these keywords must be used to handle the exception thrown by try block in some
rational manner?
(A) try
(B) finally
(C) throw
(D) catch
D
MCQ No - 5
MCQ No - 6
(A) A
(B) B
(C) AC
(D) BC
D
MCQ No - 7
Which of the following classes can catch all exceptions which cannot be caught?
(A) RuntimeException
(B) Error
(C) Exception
(D) ParentException
B
MCQ No - 8
D
MCQ No - 9
Which of the following keyword is used by calling function to handle exception thrown by
called function?
(A) throws
(B) throw
(C) try
(D) catch
A
MCQ No - 10
Which of the following handles the exception when a catch is not used?
(A) finally
(B) throw handler
(C) default handler
(D) java run time system
MCQ No - 11
A
MCQ No - 12
Which of the following should be true of the object thrown by a thrown statement?
(A) Should be assignable to String type
(B) Should be assignable to Exception type
(C) Should be assignable to Throwable type
(D) Should be assignable to Error type
C
MCQ No - 13
Which of these class is related to all the exceptions that can be caught by using catch?
(A) Error
(B) Exception
(C) RuntimeExecption
(D) All of the mentioned
B
MCQ No - 15
MCQ No - 16
(A) TypeA
(B) TypeB
(C) Compile Time Error
(D) 0TypeB
C
MCQ No - 17
(A) A
(B) B
(C) Hello
(D) Runtime Exception
D
MCQ No - 18
C
MCQ No - 19
Which of these exceptions will occur if we try to access the index of an array beyond its
length?
(A) ArithmeticException
(B) ArrayException
(C) ArrayIndexException
(D) ArrayIndexOutOfBoundsException
D
MCQ No - 20
MCQ No - 21
D
MCQ No - 22
B
MCQ No - 23
B
MCQ No - 24
A
MCQ No - 25
MCQ No - 26
Which of these can be used to fully abstract a class from its implementation?
(A) Objects
(B) Packages
(C) Interfaces
(D) None of the Mentioned
C
MCQ No - 27
A
MCQ No - 28
C
MCQ No - 29
Which of the following is the correct way of implementing an interface salary by class
manager?
(A) class manager extends salary {}
(B) class manager implements salary {}
(C) class manager imports salary {}
(D) none of the mentioned
B
MCQ No - 30
Which of the following is an incorrect statement about packages?
(A) Interfaces specifies what class must do but not how it does
(B) Interfaces are specified public if they are to be accessed by any code in the program
(C) All variables in interface are implicitly final and static
(D) All variables are static and methods are public if interface is defined pubic
MCQ No - 31
(A) 0
(B) 2
(C) 4
(D) None of the mentioned
C
MCQ No - 32
B
MCQ No - 33
A
MCQ No - 34
D
MCQ No - 35
MCQ No - 36
A
MCQ No - 37
C
MCQ No - 38
Event-driven programming
MCQ No - 01
A
MCQ No - 02
C
MCQ No - 03
A
MCQ No - 04
The _____ layout arranges all the nodes in our application in a single horizontal row.
(A) VBox
(B) FlowPane
(C) HBox
(D) TilePane
C
MCQ No - 05
The _____ layout arranges all the nodes in our application in a single vertical column.
(A) VBox
(B) FlowPane
(C) HBox
(D) TilePane
MCQ No - 06
The _____ layout arranges the nodes in our application in top, left, right, bottom and center
positions.
(A) TilePane
(B) BorderPane
(C) GridPane
(D) FlowPane
B
MCQ No - 07
The _____ layout arranges the nodes in our application on top of another.
(A) TilePane
(B) BorderPane
(C) StackPane
(D) FlowPane
C
MCQ No - 08
D
MCQ No - 09
The _____ layout anchors the nodes in our application at a particular distance from the pane.
(A) GridPane
(B) AnchorPane
(C) BorderPane
(D) TextFlow
B
MCQ No - 10
The _____ layout adds all the nodes of application in the form of uniformly sized tiles.
(A) TilePane
(B) GridPane
(C) BorderPane
(D) AnchorPane
A
MCQ No - 11
The _____ layout arranges the nodes in our application as a grid of rows and columns.
(A) TilePane
(B) GridPane
(C) BorderPane
(D) AnchorPane
B
MCQ No - 12
D
MCQ No - 13
D
MCQ No - 14
In event capturing phase, event travels to all nodes in top to bottom manner.
(A) Target Selection
(B) Route Construction
(C) Event Capturing Phase
(D) Event Bubbling Phase
C
MCQ No - 15
Event dispatch chain is created in
(A) Target Selection
(B) Route Construction
(C) Event Capturing Phase
(D) Event Bubbling Phase
MCQ No - 16
Inner class can access all the members of outer class including private data members and
methods.
(A) TRUE
(B) FALSE
Concurrency
MCQ No - 1
Which of this method can be used to make the main thread to be executed last among all the
threads?
(A) stop()
(B) sleep()
(C) join()
(D) call()
B
MCQ No - 2
Which of this method is used to find out that a thread is still running or not?
(A) run()
(B) Alive()
(C) isAlive()
(D) checkRun()
C
MCQ No - 3
C
MCQ No - 4
C
MCQ No - 5
MCQ No - 6
A
MCQ No - 7
B
MCQ No - 8
B
MCQ No - 9
D
MCQ No - 10
Which of these method of Thread class is used to find out the priority given to a thread?
(A) get()
(B) ThreadPriority()
(C) getPriority()
(D) getThreadPriority()
MCQ No - 11
Which of these method of Thread class is used to Suspend a thread for a period of time?
(A) sleep()
(B) terminate()
(C) suspend()
(D) stop()
A
MCQ No - 12
Which method of predefined class Thread is used to check whether current thread being
checked is still running?
(A) isAlive()
(B) Join()
(C) isRunning()
(D) Alive()
A
MCQ No - 13
D
MCQ No - 14
Which of the interface contains all the methods used for handling thread related operations
in Java?
(A) Runnable interface
(B) Math interface
(C) System interface
(D) ThreadHandling interface
A
MCQ No - 15
MCQ No - 16
A
MCQ No - 17
B
MCQ No - 18
(A) 1 and 3
(B) 2 and 4
(C) 1 and 2
(D) 2 and 5
C
MCQ No - 19
(A) 1 and 4
(B) 2 and 3
(C) 3 and 4
(D) 2 and 4
A
MCQ No - 20
MCQ No - 21
A
MCQ No - 22
(A) My Thread
(B) Thread[My Thread,5,main]
(C) Compilation Error
(D) Runtime Error
B
MCQ No - 23
(A) My Thread
(B) Thread[My Thread,5,main]
(C) Exception
(D) Runtime Error
MCQ No - 24
(A) 0
(B) 1
(C) TRUE
(D) FALSE
MCQ No - 25
(A) TRUE
(B) FALSE
(C) truetrue
(D) falsefalse
MCQ No - 26
(A) My Thread
(B) Thread[My Thread,5,main]
(C) Compilation Error
(D) Runtime Error
A
MCQ No - 27
(A) My Thread
(B) Thread[My Thread,5,main]
(C) Compilation Error
(D) Runtime Error
B
MCQ No - 28
D
MCQ No - 29
}
class multithreaded_programing
{
public static void main(String args[])
{
newthread obj1 = new newthread("one");
newthread obj2 = new newthread("two");
try
{
Thread.sleep(1000);
System.out.print(obj1.t.isAlive());
}
catch(InterruptedException e)
{
System.out.print("Main thread interrupted");
}
}
}
(A) TRUE
(B) FALSE
(C) Main thread interrupted
(D) None of the mentioned