ET MCQ Practice Questions
ET MCQ Practice Questions
int a = Integer.parseInt(str);
System.out.println(a);
A)1
B)12
C)123
D)Error
B)twoone
C)one
D)two
Q3. When an String is passed to a method, what does the method receive?
a) Copy of an string
b) Reference of an string
c) Value of index
d) None of the above
Q5.
How many objects will be created in the following?
A)2
B)3
C)4
D)5
Q6.
a) abc
b) ab
c) bc
d) b
Q10.
compareTo() returns
a) An int value
b) False
c) True
d) None
Q11.
What is the output of the following JAVA program ?
Class Test {
obj.start();
void start() {
System.out.print(stra);
return“ good”;
a) dogood : dogood
B) dogood : dogoodgood
C) dogood : gooddogood
D) dogood : dodogood
i) JVM
j) JRE
k) JDK
l) JDB
Q13. Evaluate the following Java expression, if x=3, y=5, and z=10:
++z + y - y + z + x++
a) 24
b) 23
c) 20
fi
fi
d) 25
class Test
System.out.println(s);
char array[] = {'a', 'b', ' ', 'c', 'd', ';', 'e', 'f', ' ',
obj.demo(str);
a) ab cd
ef gh
ij kl
b) ab
c) None
Q21. Find predicted output of given program which is used to add and delete elements using Stack.
class mcq
{
public static void main(string args[])
{
Stack obj = new Stack();
obj.push(new Integer(4);
obj.push(new Integer(2));
obj.pop();
obj.push(new Integer(5));
System.out.println(obj);
}
}
a) [4, 5]
b) [3, 2]
c) [3, 2, 5]
d) [3, 5, 2]
fi
fi
r
Q25.
How many objects will be created in the following?
A)2
B)3
C)4
D)5
Q26.
Q30.
compareTo() returns
a) An int value
b) False
c) True
d) None
Q31.
What is the output of the following JAVA program ?
Class Test {
obj.start();
void start() {
System.out.print(stra);
return“ good”;
a) dogood : dogood
B) dogood : dogoodgood
C) dogood : gooddogood
D) dogood : dodogood
e) JVM
f) JRE
g) JDK
h) JDB
Q33. Evaluate the following Java expression, if x=3, y=5, and z=10:
++z + y - y + z + x++
a) 24
b) 23
c) 20
fi
fi
d) 25
class Test
System.out.println(s);
char array[] = {'a', 'b', ' ', 'c', 'd', ';', 'e', 'f', ' ',
obj.demo(str);
a) ab cd
ef gh
ij kl
b) ab
c) None
A.
B. Hell
C. Runtime Erro
D. Compilation Erro
Q42. Find predicted output of given program which is used to add and delete elements using Stack.
class mcq
{
public static void main(string args[])
{
Stack obj = new Stack();
obj.push(new Integer(4);
obj.push(new Integer(2));
obj.pop();
obj.push(new Integer(5));
System.out.println(obj);
}
}
a) [4, 5]
b) [3, 2]
c) [3, 2, 5]
d) [3, 5, 2]
Q44. Which of the following is incorrect statement regarding the use of generics and parameterized
types in Java
A. Generics provide type safety by shifting more type checking responsibilities to the compile
B. Generics and parameterized types eliminate the need for down casts when using Java Collection
C. When designing your own collections class (say, a linked list), generics and parameterized types
allow you to achieve type safety with just a single class de nition as opposed to de ning multiple
classe
D. All of the mentione
fi
fi
r
}
a) character =65
b) Compilation Error
c) character =F
d) character =”65”
Q46.
How many objects will be created in the following?
A)2
B)3
C)4
D)5
Q47.
System.out.println("Class Sub");
}
}
a) Class Super
b) Class Sub
c) foo() in Sub cannot override foo() in Super
d) The statement “Super s = new Sub();” is illegal.
Q51.
compareTo() returns
a) An int value
b) False
c) True
d) None
Q52.
What is the output of the following JAVA program ?
Class Test {
obj.start();
void start() {
System.out.print(stra);
return“ good”;
a) dogood : dogood
B) dogood : dogoodgood
C) dogood : gooddogood
D) dogood : dodogood
e) JVM
f) JRE
g) JDK
h) JDB
Q54. Evaluate the following Java expression, if x=3, y=5, and z=10:
++z + y - y + z + x++
a) 24
b) 23
c) 20
fi
fi
d) 25
class Test
System.out.println(s);
char array[] = {'a', 'b', ' ', 'c', 'd', ';', 'e', 'f', ' ',
obj.demo(str);
a) ab cd
ef gh
ij kl
b) ab
c) None
A.
B. Hell
C. Runtime Erro
D. Compilation Erro
Q63. Which one of the following will declare an array and initialize it with five numbers?
a) Public
b) Protected
c) private
Q72 . Which of these keywords must be used to handle the exception thrown by try block in a java
code ?
a) try
b) finally
c) throw
d) catch
Q73.
public class Main {
public static void main(String arg[]) {
int i;
for (i = 1; i <= 12; i += 2) {
if (i == 8) {
System.out.println(i);
break;
}
}
}
}
a) 1
b) No output
c) 8
d) 1357911
Q74.
class Hello
{
static int a;
static
{
a = 14;
System.out.println ("inside static block");
System.out.println ("a = " + a);
}
Test()
{
System.out.println ("inside constructor");
a = 10;
}
}
}
a) 11511
b) 1105110
c) 115110
d) 27
Q77.
public class Hello {
public static void main(String[] args) {
TreeSet<String> treeSet = new TreeSet<>();
treeSet.add("Sky");
treeSet.add("Is");
treeSet.add("Blue");
treeSet.add("SkyIsBlue");
for (String temp : treeSet)
System.out.print(temp + " ");
System.out.println("\n");
}
}
A. Blue Is Sky SkyIsBlue
B. Is Sky Blue SkyISblue
C. Blue Sky Is
D. SkyIsBlue
class Main
{
public static void main(String args[])
{
try
{
System.out.print("Hello" + " " + 1 / 0);
}
catch(ArithmeticException e)
{
System.out.print("World");
}
}
}
A. Hello
B. World
C. HelloWorld
D. Hello World
Q79
import java.util.ArrayList;
class Demo {
public void show()
{
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(4);
list.add(7);
list.add(1);
for (int number : list) {
System.out.print(number + " ");
}
}
} public class Main {
public static void main(String[] args)
{
Demo demo = new Demo();
demo.show();
}
}
A. Compilation Error
B. 4 7 1
C. 1 4 7
D. None
Q80
int values[ ] = {1,2,3,4,5,6,7,8,9,10};
for(int i=0;i< Y; ++i)
System.out.println(values[i]);
Find the value of value[i]?
a. 10
b. 11
c. 15
d. None of the above
package pkg;
class output {
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello");
s1.setCharAt(1, x);
System.out.println(s1);
}
}
a) xello
b) xxxxx
c) Hxllo
d) Hexlo
for(int i=0;i<x.length;i++) {
System.out.print(y[i]+" ");
}
}
}
a) 1234
b) 0000
c) 12
d) 00
Q85 The OutputStreams includes methods that are designed to perform the following tasks.
i) closing streams ii) flushing streams
iii) reading bytes iv) writing bytes
Q87 . Which of these classes is not part of the Collection framework in Java?
a) Queue
b) Stack
c) ArrayList
d) Map
Q88. Threads ar
a) light weight process
b) heavyweight process
c) both
d) none
Q89.
int a = 2, b = 3, c = 4, d = 5;
float k = 4.3f;
System.out.println (c=c++);
1. 2
2. 4
3. 5
4. 8
}
a) 10 20 30 40 50
b) Compile Time Error
c) Runtime Error
d) 10 20 30 40
class Test {
public static void main(String[] args) {
for(int i = 0; 0; i++)
{
System.out.println("Hello");
break;
}
}
}
a) Hello
b) Empty Output
c) Compiler error
d) Runtime error
Q92.
class Main {
public static void main(String args[]) {
int t;
System.out.println(t);
}
}
Class Super
a) 0
b) Error
c) 1
d) Garbage value
Q93.
class Test
{
public static void main (String[] args)
{
int arr1[] = {1, 2, 3};
int arr2[] = {1, 2, 3};
if (arr1 == arr2)
System.out.println("Same");
else
System.out.println("Not Same");
}
}
Q94.
What is the output of this program?
import java.util.LinkedList;
class Demo {
list.add("Element1"); // line 6
list.add("Element2");
System.out.print(list.getFirst()); // line 8
demo.show();
A. Element1
C. Runtime Error
D. Element2
Q95. What will be the output of the following java code?
class A {
public void aMethod() {
System.out.println("a Method from A");
}
}
class B extends A {
public void aMethod() {
System.out.println("a Method from B");
}
}
public class Main {
public static void main(String ar[]) {
A a = new B();
a.aMethod();
}
}
a) a Method from A
b) a Method from B
c) Compilation Error
d) Runtime Exception
for(int i=0;i<x.length;i++) {
System.out.print(y[i]+" ");
}
}
}
a) 1234
b) 0000
c) 12
d) 00
Q97.
import java.util.*;
class Demo {
public void show()
{
List<Integer> list = new LinkedList<Integer>();
list.add(1);
list.add(4);
list.add(7);
list.add(5);
Collections.sort(list); // line 8
System.out.println(list);
}
} public class Main {
public static void main(String[] args)
{
Demo demo = new Demo();
demo.show();
}
}
A. Compilation Error at line 9
B. [1, 4, 5, 7]
C. [1, 4, 7, 5]
D. Runtime Error
a) false
b) true
c) ClassCastException at runtime
d) Compile-time error
Q 99 import java.util.*;
System.out.println("\n");
}
}
a) 1 2 4
b) 1 2 2 4
c) 4 2 2 1
d) Compile-time error
a) 11511
b) s1105110
c) 51105110
d) 27
class Main
{
public static void main(String args[])
{
try
{
System.out.print("Hello" + " " + 1 / 0);
}
catch(ArithmeticException e)
{
System.out.print("World");
}
}
}
A. Hello
B. World
C. HelloWorld
D. Hello World
System.out.println(hashSet);
}
}
ff
Q105.What is the Java Collections Framework?
a) A set of classes and interfaces implementing complex collection data structures
b) A set of classes and interfaces implementing simple collection data structures
c) A set of classes and interfaces implementing complex algorithms
d) A set of classes and interfaces implementing simple algorithms
a) 100
b) 200
c) 300
d) 400
a) 11511
b) 1105110
c) 115110
d) 27
a) Exception Finally
b) Exception
c) Finally Exception
d) none of the above
class GenericsExample {
public static void main(String[] args) {
GenericClass<Integer> gc1 = new GenericClass<>(10);
GenericClass<String> gc2 = new GenericClass<>("Hello");
System.out.println(gc1.getData());
System.out.println(gc2.getData());
}
}
class GenericClass<T> {
private T data;
public T getData() {
return data;
}
}
a) 10 Hello
b) Hello 10
c) Error
d) None of the above
fi
Q117.What are the two ways to create a thread in Java?
a) By extending the Thread class
b) By implementing the Runnable interface
c) By using Collection framework
d) Both a and b
a) true
b) can be either true or false
c) Compilation error
d) false
a) 10
b) 20
c) 30
d) 40
Q134.What is the superclass of all errors and exceptions in the Java language?
a) RunTimeExceptions
b) Throwable
c) Catchable
d) None of the above
a) Exception
b) Exception Finally
c) Finally
d) none of the above
class GenericsExample {
public static void main(String[] args) {
GenericClass<Integer> gc1 = new GenericClass<>(10);
GenericClass<String> gc2 = new GenericClass<>("Hello");
System.out.println(gc1.getData());
System.out.println(gc2.getData());
}
}
class GenericClass<T> {
private T data;
public T getData() {
return data;
}
fi
}
a) 10 Hello
b) Hello 10
c) Error
d) None of the above
a) true
b) false
c) Compilation error
d) None of the above