L1 MCQ's
L1 MCQ's
Score 1.00 of 1
Question:
When the switch statement matches the expression with the given labels,
how is the comparison done?
Response:
Both the datatype and the result of the expression are compared
Only the datatype of the expression is compared
Only the value of the expression is compared
None of the above
Score 1.00 of 1
Question:
What will be the output of the following code snippet?a = [1, 2, 3, 4,
5];print(a.slice(2, 4));
Response:
3, 4
2, 3
3, 4, 5
2, 3, 4
Score 1.00 of 1
Question:
What will be the output of the following code snippet?<script
type="text/javascript" language="javascript"> var x=12;var y=8;var
res=eval("x+y");document.write(res); </script>
Response:
20
x+y
128
None of the above
Score 1.00 of 1
Question:
What will be the output of the following code snippet?let sum = 0;
const a = [1, 2, 3];a.forEach(getSum);print(sum);function getSum(ele) {
sum += ele;}
Response:
6
1
2
None of the above
Score 1.00 of 1
Question:
What will be the output of the following code snippet?(function(){
setTimeout(()=> console.log(1),2000); console.log(2); setTimeout(()=>
console.log(3),0); console.log(4);})();
Response:
1234
2341
2431
4321
Score 1.00 of 1
Question:
What will be the output of the following code snippet?var a =
Math.max() < Math.min();var b = Math.max() >
Math.min();print(a);print(b)
Response:
true false
false true
true true
false false
Score 1.00 of 1
Question:
Which of the following methods is used to access HTML elements using
Javascript?
Response:
getElementbyid()
getElementsByClassName()
Both A & B
None of the above
Score 1.00 of 1
Question:
The loop will run 3 times, before meeting the exit condition. First
value of b will be 2 * 2 = 4, followed by 4 + 3 * 2 = 10, and then
value of 10 + 4 * 2 = 18.
Response:
It will debug all the errors in the program at runtime
It acts as a breakpoint in a program
It will debug erroe in the current statement if any
All of the above
Score 1.00 of 1
Question:
Upon encountering empty statements, what does the Javascript
Interpreter do?
Response:
Throws an error
Ignores the statements
Gives a warning
None of the above
Score 1.00 of 1
Question:
What will be the output of the following code snippet? <script
type="text/javascript">a = 5 + "9";document.write(a);</script>
Response:
Compilation Error
14
Runtime Error
59
Score 1.00 of 1
Question:
What will be the output of the following code snippet?(function(a){
return (function(){ console.log(a); a = 6; })()})(21);
Response:
6
NaN
21
None of the above
Score 1.00 of 1
Question:
What will be the output of the following code snippet?function
solve(arr, rotations){ if(rotations == 0) return arr; for(let i = 0; i
< rotations; i++){ let element = arr.pop(); arr.unshift(element); }
return arr;}// solve([44, 1, 22, 111], 5);
Response:
[111, 44, 1, 22]
[44, 1, 22, 111]
[111, 44, 1, 22]
[1, 22, 111, 44]
Score 1.00 of 1
Question:
What does the 'toLocateString()' method do in JS?
Response:
Returns a localised object representation
Returns a parsed string
Returns a localized string representation of an object
None of the above
Score 1.00 of 1
Question:
What will be the output of the following code snippet?var a = true +
true + true * 3;print(a)
Response:
3
0
Error
5
Score 1.00 of 1
Question:
What will be the output of the following code
snippet?print(typeof(NaN));
Response:
Object
Number
String
None of the above
Score 1.00 of 1
Question:
What is the output of the following code snippet?print(NaN === NaN);
Response:
TRUE
FALSE
undefined
Error
Score 1.00 of 1
Question:
When an operator's value is NULL, the typeof returned by the unary
operator is:
Response:
Boolean
Undefined
Object
Integer
Score 1.00 of 1
Question:
What will be the output for the following code snippet?<p
id="example"></p> <script> function Func() {
document.getElementById("example").innerHTML=Math.sqrt(81); } </script>
Response:
9
81
Error
0
Score 1.00 of 1
Question:
What will be the output of the following code snippet? <script
type="text/javascript" language="javascript"> var a = "Scaler";var
result = a.substring(2, 4);document.write(result); </script>
Response:
al
ale
cal
caler
Score 1.00 of 1
Question:
What will be the output of the following code snippet?var a = 1; var b
= 0; while (a <= 3) { a++; b += a * 2; print(b);}
Response:
4 10 18
123
147
None of the above
Question Results
Score 1.00 of 1
Question:
Given the following definition of a class, which fields are accessible
from outside the package com.corporation.project?package
com.corporation.project;public class MyClass{int i;public int
j;protected int k;private int l;}
Response:
server.port
spring.port
port
server
server.spring.port
Score 1.00 of 1
Question:
How many objects will be created in the following?String a = new
String("Interviewbit");String b = new String("Interviewbit");Strinc c =
"Interviewbit";String d = "Interviewbit";
Response:
3
2
4
5
1
Score 1.00 of 1
Question:
Look at the below given code @Entity@Table(name =
"EMPLOYEE")@Access(value=AccessType.FIELD)public class Employee
{@Id@GeneratedValue(strategy = GenerationType.IDENTITY)@Column(name =
"emp_id")private long id;@Column(name = "emp_name")private String
name;@OneToOne(mappedBy = "employee")@Cascade(value =
org.hibernate.annotations.CascadeType.ALL)private Address
address;//getter setter methods} which of the statement are correct
regarding above code
Response:
A table Employee will be generated with no colum
A table employee will be gnerated with name column
A table with name Employee will be generated having attributes id and name
having OneToOne relation with Address entity
A table Employee will be generated with id column
no table will be generated
Score 1.00 of 1
Question:
package samplequestions;public class Sample {public static void
main(String[] args) {// TODO Auto-generated method stubint[] x = {120,
200, 016}; for(int i = 0; i < x.length; i++){ System.out.print(x[i] + "
");}}}
Response:
120 200 16
120 200 14
120 200
200 16
12 16
Score 1.00 of 1
Question:
Identify the infinite loop.
Response:
for(;;)
for(int i=0;i<!0;i--)
for(int i=0;;i++)
All of the above
none of the above
Score 1.00 of 1
Question:
Predict the output of below codepackage samplequestions;public class
Sample {public static void main(String[] args) {int count = 0;do{
System.out.println("Interviewbit"); count++;} while(count < 10);}}
Response:
11431
1 4 3 11
14131
11111
144 331
Score 1.00 of 1
Question:
what is the error in the following class definitions?abstract class
xy{abstract sum (int x, int y) { }}
Response:
class cannot be abstract
abstract method cannot have body
method cannot be abstract
we cannot have abstract method inside abstract class
none of the above
Score 1.00 of 1
Question:
Which one of the following class definitions is a valid definition of a
class that cannot be instantiated?
Response:
s1==s2
s1!=s2
s1=s2
s1==s3
s2==s3
Score 0.00 of 1
Question:
What's true about the following @Entity association between House and
Window?@Entitypublic class Window {@Idprivate int
winNo;@ManyToOneprivate House aHouse;}@Entitypublic class House
{@Idprivate int houseNo;@OneToMany(mappedBy="aHouse")private List
windows;
Response:
It's OneToMany unidirectional association
The association owner is the House class
The association owner is the Window class
The association owner is the Window class
none of the above
Score 1.00 of 1
Question:
What does ViewResolver do
Response:
It generates a view by mapping a logical view name returned by a controller
method to a view technology
It supports internatinalization of web applications by detecting a user's locale
It creates a unique view determined by the user's browser type ,supporting cross
browser compatibility
It maps custom parameter to SQL views in database
none of the above
Score 1.00 of 1
Question:
Predict the output of below codepackage samplequestions;public class
Sample {public static void main(String[] args) {// TODO Auto-generated
method stub byte x = 127; x++; x++; System.out.print(x);}}
Response:
127
-127
0
-1
compile time error
Score 1.00 of 1
Question:
Which of these field declarations are legal within the body of an
interface?
Response:
public int val=100
int val=100
public static final int val=100
public static int val=100
none of the above
Score 1.00 of 1
Question:
Predict the output of below codepackage samplequestions;public class
Sample {public static void main(String[] args) {String str =
"abcde";System.out.println(str.substring(1, 3));}}
Response:
abc
bc
abcd
bcd
cde
Score 1.00 of 1
Question:
How does Spring generate bean names for classes annotated with
@Component that do not specify a name
Response:
It uses sort name of the classes
It uses short name of the class in upper case
It uses cannonical name of the class in lower case
It uses short name of the classes with first letter in lower case
A bean cannot be created for such a class
Score 1.00 of 1
Question:
Predict the output of below codepackage samplequestions;public class
Sample {public static void main(String[] args) {// TODO Auto-generated
method stubString str;int fname;str="Foolish
boy";fname=str.indexOf("fool"); System.out.println(fname);}}
Response:
0
3
1
-1
2
Question Results
Score 1.00 of 1
Question:
How to auto-inject in an attribute a bean by its name?
Response:
With the name attribute of the @Autowired annotation
Using the unique @Qualifier annotation
Using the @Autowired and @Qualifier spring annotations
Score 1.00 of 1
Question:
Which of the following is correct output?public class DemoFun {public
static void main(String[] args) { List<Integer> numbers =
Arrays.asList(2,3,4,5,2); Set<Integer> squareSet =
numbers.stream().map(x->x*x).collect(Collectors.toSet());
System.out.println(squareSet);}}
Response:
a) [16, 4, 9, 25]
b) [16,4,9,25,4]
c) [4,9,16,25,4]
d) [4,4,16,25,9]
Score 0.00 of 1
Question:
Given below code snippetFor the Given Code snippet () -> 7 * 12.0;
Which of the following interfaces can provide the functional descriptor
for the above lambda expression?
Response:
a) interface A { default double m() { return 4.5; }}
b)interface B { int m(int a,int b);}
c) interface C { int m();}
d)interface D { double m(Integer... i);}
Score 1.00 of 1
Question:
What's true about the following @Entity association between House and
Window?public class Window { @Id private int winNo; @ManyToOne private
House aHouse;}@Entitypublic class House { @Id private int houseNo;
@OneToMany(mappedBy="aHouse") private List windows;}
Response:
It's OneToMany unidirectional association
It's OneToMany bidirectional association
The association owner is the House class
The association owner is the Window class
Score 1.00 of 1
Question:
Choose the output for following code snippet.public class DemoFun
{public static void main(String[] args) { Stream.of("eeny ", "meeny ",
null).forEach(DemoFun::toUpper); } private static void toUpper(String
str) { Optional <String> string = Optional.ofNullable(str);
System.out.print(string.map(String::toUpperCase).orElse("dummy")); }}
Response:
a) test-10 test-10
b) test-10
c)RunTimeException
d)Compilation Failure
Score 1.00 of 1
Question:
Consider the following code:
public class MyClass { private boolean check(String arg) { System.out.println(arg); assert arg !=
null; // Line 1 return !arg.isBlank(); } String m1(String arg) { assert arg != null; // Line 2 // do
something assert check(arg); // Line 3 return arg.trim(); } public String m2(String arg) { assert arg
!= null; // Line 4 String output = m1(arg); assert output != null; // Line 5 return output; } }
On which three lines assertions are used properly?
Response:
Lines 1, 2 & 3
Lines 3, 4 & 5
Line 1, 2 & 5
Line 2, 3 & 5
Score 1.00 of 1
Question:
class Employee {
int id;
String name;
public Employee() { }
public Employee(int id, String name) {
this.id = id; this.name = name; } //setters and getters}
public class ComparableTest {
public static void main(String[] args) {
List list = new ArrayList<>();
list.add(new Employee(123, "Sugan"));
list.add(new Employee(101, "Kavita"));
list.add(new Employee(132, "Anju"));
Comparator comparator = (a, b) -> { return a.getName().compareTo(b.getName()); };
list.sort(comparator); list.forEach(e -> System.out.println(e.getName())); }}
Response:
SuganKavitaAnju
AnjuKavitaSugan
KavitaSuganAnju
Compilation fails
Score 1.00 of 1
Question:
Predict the output. import java.util.ArrayList;public class
CollectionFramework { public static void main(String argvs[]) {
ArrayList al = new ArrayList(); al.add("X"); al.add("Y"); al.add("Z");
al.add(1, "B"); System.out.print(al); }}
Response:
[X, Y, B, Z]
[X, B, Z]
[X, B, Y, Z]
[X, Z, Y, B]
Score 0.00 of 1
Question:
Which one of the following are not valid lambda expression?
Response:
() -> {}
() ->"Hello"
{return "Hello"•;}
(Integer i) -> return Hello"
Score 1.00 of 1
Question:
public class ForEachExample {
public static void main(String[] args) {
List gamesList = new ArrayList();
gamesList.add("Football"); gamesList.add("Cricket");
gamesList.add("Chess"); gamesList.add("Hocky");
gamesList.add("Cricket"); gamesList.add("Chess");
gamesList.add("Football"); gamesList.add("null");
gamesList.add(null);
Set set = gamesList.stream().collect(Collectors.toSet()); set.forEach(game ->
System.out.println(game)); }}
Response:
ChessHockynullCricketnullFootball
ChessHockynullCricketFootball
FootballCricketChessHockyCricketChessFootballnull
FootballCricketChessHockyCricketChessFootballnullnull
Score 1.00 of 1
Question:
Which is the new method introduced in java 8 to iterate over a collection?
Response:
for (String i : StringList)
foreach (String i : StringList)
StringList.forEach()
List.for()
Score 0.00 of 1
Question:
Suppose you have to get the names with course and age where age is
neither 25 nor 26. Which of the following is the correct query for
this?
Response:
SELECT Names FROM Students WHERE Age NOT EXISTS (25', '26')
SELECT Names FROM Students HAVING Age NOT EXISTS (25', '26')
Score 1.00 of 1
Question:
Which of the given option is correct for adding exception to the test
method given below? Public void
divideByZeroTest(){calobj.divide(15,0);} Note: calobj is an object of
Calculate class which contains divide(int x,int y) method.
Response:
@Test(expected = ArithmeticException.class)
@Test( ArithmeticException.class)
@Before( ArithmeticException.class)
@Before(expected = ArithmeticException.class)
Score 1.00 of 1
Question:
Suppose you have to get the Name, Age and Salary of the Employees with salaries
in the range
of 30000 to 50000. Which of the following queries would be correct for this?
Response:
Options 3 & 4
Options 1 & 2
Score 0.00 of 1
Question:
What would be the output of the following codeclass exception_handling
{ public static void main(String args[]) { try {
System.out.print("A"); throw new NullPointerException ("Hello"); }
catch(ArithmeticException e) { System.out.print("B"); } } }
Response:
A
B
Hello
a ,RunTimeException
Score 1.00 of 1
Question:
Consider the following code:import java.nio.file.*; import java.io.*;
class NIO { public static void main(String [] args)throws IOException {
Path path = Paths.get("data.txt"); File myfile = new
File(path.toString()); myfile.createNewFile(); } }Given that the
current working directory is empty, which one of the given options are
true?
Response:
Compilation fails
Compilation succeeds and a file called "data.txt" will be created in the root
directory
As there is no file called "data.txt" the Paths class' "get()" method will cause a
compile-time error
Compilation succeeds and a file called "data.txt" will be created in the current
working directory
Question Results
Score 1.00 of 1
Question:
Which one is a template for creating different objects
Response:
Array
Class
Interface
Method
Score 1.00 of 1
Question:
Which of the following are not Java modifiers?
Response:
public
private
friendly
protected
Score 1.00 of 1
Question:
Which of the following is a correct implementation of method
overloading?
Response:
void methodA(){} int methodA(){}
void methodA(){} void methodA(int a){}
void methodA(){} int methodB(int a){}
int methodA(){} int methodAA(){}
Score 1.00 of 1
Question:
Which is correct about an instance variable of type String
Response:
It defaults to an empty string.
It defaults to null
It does not have a default value
It will not compile without initializing on the declaration line
Score 1.00 of 1
Question:
How many Primitive Data types are there in Java
Response:
7
8
6
10
Score 1.00 of 1
Question:
Size of primitive int is......bytes
Response:
1 bytes
3 bytes
4 bytes
8 bytes
Score 1.00 of 1
Question:
Which provides runtime environment for java byte code to be executed?
Response:
JDK
JVM
JRE
JAVAC
Score 1.00 of 1
Question:
What is the default return type of the class members in the class?
Response:
default
private
protected
public
Score 1.00 of 1
Question:
What is garbage collection in the context of Java
Response:
Java deletes all unused java files on the system
Memory used by the object with no reference is automatically reclaimed.
The JVM cleans output of Java program with error.
Any unused package in a program automatically gets deleted.
Score 1.00 of 1
Question:
Which of the following declarations does not compile
Response:
Response:
List<String> obj = new LinkedList<String> ();
TreeSet<String> obj = new TreeSet<String> ();
HashSet<String> obj = new HashSet<String> ();
Queue<String> obj= new PriorityQueue<String> ();
Score 1.00 of 1
Question:
Which of the following methods of the File class will delete a
directory or file?
Response:
The file class does not allow you to delete a file or directory
remove()
delete()
deleteFile()
Score 1.00 of 1
Question:
class Demo{public static void main(String []args){Path javaHome =
Paths.get("C:/Program Files/Java/jdk1.8.0_25");
System.out.println(javaHome.getNameCount());}}
What will be the output of above code?
Response:
1
2
3
4
Score 1.00 of 1
Question:
A programmer has an algorithm that requires a java.util.List that
provides an efficient implementation of add(0,object), but does NOT
need to support quick random access. What supports these requirements?
Response:
ArrayList
Queue
Linear List
LinkedList
Score 1.00 of 1
Question:
What will happen after the execution of below code?
public class HashSetTest { public static void main(String[] args) {
Set haseSet = new HashSet<>(); haseSet.add("1"); haseSet.add(1);
haseSet.add("null"); haseSet.add(null); System.out.println(haseSet);
}}
Response:
[null, 1, 1, null]
[1,null]
[null,1,null]
[1,1,null]
Score 1.00 of 1
Question:
Predict the output of following Java program:
class Main { public static void main(String args[]) { try {
throw 10; } catch(int e) { System.out.println("Got
the Exception " + e); } }}
Response:
Got the Exception 10
Got the Exception 0
Compilation fails
None of the above
Score 1.00 of 1
Question:
What will be the output of the following Java code?
public class ThreadDemo { public static void main(String args[]) {
Thread t = Thread.currentThread();
System.out.println(t.getPriority()); }}
Response:
1
10
5
undefined
Score 1.00 of 1
Question:
Which of the given method must be overridden by a class, after
implementing Comapartor?
Response:
int compare(Object obj);
int compareTo(Object obj);
int compareTo(Object obj1,Object obj2);
int compare(Object obj1,Object obj2);
Score 1.00 of 1
Question:
________ is raised if I do not provide the String array as the argument
to the main method.
Response:
NullPointerException
IllegalAccessException
NoSuchMethodError
None of the above
Score 1.00 of 1
Question:
Which among the following Sets maintains insertion order?
Response:
HashSet
TreeSet
LinkedHashSet
Both B & C
Score 1.00 of 1
Question:
When the JVM runs out of memory, which exception will be thrown?
Response:
MemoryBoundException
OutOfMemoryError
OutOfMemoryException
OutOfRangeException
Score 1.00 of 1
Question:
try { int number = Integer.parseInt("two"); }Which could be used to
create an appropriate catch block?
Response:
ClassCastException
IllegalStateException
NumberFormatException
None of the above is 'True
Score 1.00 of 1
Question:
What will be the output of following program?
public class Foo { public static void main(String[] args) {
try { return; } finally {
System.out.println( "Finally" ); } } }
Response:
Finally
Compilatation fails
No output
Runtime Exception
Score 1.00 of 1
Question:
Which of the following I/O classes helps you in persistence storage of
Objects?
Response:
ObjectOutputStream
DataOutputStream
FileWriter
ObjectWriter
Score 1.00 of 1
Question:
A _______ is used to walk through a collection and can remove elements
from the collection during the iteration.
Response:
Enumeration
Iterator
ArrayList
Vector
Score 1.00 of 1
Question:
Which of these exception is thrown in cases when the file specified for
writing is not found?
Response:
IOException
FileException
FileNotFoundException
FileInputException
Score 0.00 of 1
Question:
What will be the output of below code?
class Test{ public static void main(String[] args) { try { int a[]=
{1, 2, 3, 4}; for (int i = 1; i <= 4; i++) { System.out.println
("a[" + i + "]=" + a[i] + "n"); } } catch (Exception e) {
System.out.println ("error = " + e); } catch
(ArrayIndexOutOfBoundsException e) { System.out.println
("ArrayIndexOutOfBoundsException"); } }}
Response:
Compiler error
Run time error
ArrayIndexOutOfBoundsException
a[1]=2na[2]=3na[3]=4n
Score 1.00 of 1
Question:
Predict the output of the following program:
abstract class demo { public int a; demo() { a = 10; } abstract
public void set(); abstract final public void get();}class Test extends
demo { public void set(int a) { this.a = a; } final public void get()
{ System.out.println("a = " + a); } public static void main(String[]
args) { Test obj = new Test(); obj.set(20); obj.get(); }}
Response:
a = 10
a = 20
compilation error
runtime error
Score 0.00 of 1
Question:
Which of these is not a correct statement?
Response:
Every class containing abstract method must be declared abstract
Abstract class defines only the structure of the class not its implementation
Abstract class can be initiated by new operator
Abstract class can be inherited
Score 1.00 of 1
Question:
What will happen after the execution of below code?
class CreateObject{public static void main(String []args){Set set = new
TreeSet();set.add("Priya");set.add("Ritu");set.add(100);}}
Response:
All elements will be successfully added to set
last element 100 will not be added to set
ClassCastException
IlleagalStateException
Score 1.00 of 1
Question:
What is the output of the following?
import java.util.*;public class Test {public static void main(String[]
args) { Set set = new TreeSet(); set.add("anu"); set.add("anil");
set.add("sunil"); for(Object str:set){ System.out.print(str + " ");}}}
Response:
Response:
'True
'False
prints number of bytes in file
prints number of characters in the file
Score 1.00 of 1
Question:
Which of these values is returned by read() method is end of file (EOF)
is encountered?
Response:
1
-1
Null
Score 1.00 of 1
Question:
What will be the output?
interface A{ public void method();}class One{ public void method(){
System.out.println("Class One method"); }}class Two extends One
implements A{ public void method(){ System.out.println("Class Two
method"); }}public class Test extends Two{ public static void
main(String[] args){ A a = new Two(); a.method(); }}
Response:
will print Class One method
will print Class Two method
compiles fine but print nothing
Compilation Error
Score 1.00 of 1
Question:
How can you ensure all threads that started from main must end in order
in which they started and also main should end in last?
Response:
join() method
sleep() method
wait() method
run() method
Score 1.00 of 1
Question:
Which collection class allows you to grow or shrink its size and
provides indexed access to its elements, but whose methods are not
synchronized?
Response:
java.util.HashSet
java.util.Vector
java.util.ArrayList
java.util.List
Score 1.00 of 1
Question:
What is the output of the following program?
class Test {public static void main(String[] args) {try
{doMath(5);System.out.print("hi");}finally { System.out.println(" from
finally"); }}public static void doMath(int den) {int num = 7 / den;}}
Response:
hi from finally
hifrom finally
prints hi from finally 2 times
None of the above
Score 1.00 of 1
Question:
What will happen after the execution of below code?
public class HashSetTest { public static void main(String[] args) {
Map map = new HashMap(); map.put(new String("a"), "Audi");
map.put(new String("a"), "Ferrari"); System.out.println(map); }}
Response:
{a=Ferrari}
{a=Audi}
{a=Audi,a=Ferrari}
{a=Ferrari,a=Audi}
compilation fails
Score 0.00 of 1
Question:
What state does Thread enter in when it has been created and started?
Response:
new
runnable
running
waiting
Score 1.00 of 1
Question:
Which of the following statements are 'True related to exception
handling in java?
Response:
UserDefined exception can be created by extending from RunTimeException
class
Throwable is the base class of Error and Exception class
Checked Exception need to be handled either by try and catch block or by using
throws keyword in a code before compilation.
All of the above
Score 1.00 of 1
Question:
Predict the output of following Java program:
class Test extends Exception { } class Main { public static void
main(String args[]) { try { throw new Test(); }
catch(Test t) { System.out.println("Got the Test Exception");
} finally { System.out.println("Inside finally block ");
} }}}
Response:
Response:
abc
abcd
abcde
Compilation fails
Score 1.00 of 1
Question:
class DemoCmp //line 1{int number;public DemoCmp(int
num){number=num;}//line 2}public class CreateDemo {public static void
main(String []args){TreeSet<DemoCmp>set = new
TreeSet<DemoCmp>();set.add(new Demo(8));set.add(new
Demo(2));set.add(new Demo(3));}}
Which code need to be inserted at line 1 and line 2for successful
execution of above code?
Response:
//line 1class DemoCmp implements Comparable//line
2public int compareTo(Object obj){return number-
obj.number;}
//line 1class DemoCmp implements Comparator//line
2public int compare(Object obj1,Object obj2){return
obj1.number-obj2.number;}
//line 1class DemoCmp implements Comparable//line
2public int compare(Object obj1,Object obj2){return
obj1.number-obj2.number;}
//line 1class DemoCmp implements Comparator//line
2public int compareTo(Object obj){return number-
obj1.number;}
Score 1.00 of 1
Question:
class GenericsDemo{ T data; public GenericsDemo(T data) { this.data =
data; }}
Which of the given statement is 'True about above code?
Response:
GenericsDemo object can be created by passing any type of parameter+B22:C24
GenericsDemo object can be created as given belowGenericsDemo<String>obj
= new GenericsDemo<String>();
GenericsDemo object can be created as given belowGenericsDemo<String>obj
= new GenericsDemo<String>("xyz");
Can not create object of given class
Score 1.00 of 1
Question:
Which of the given statement will ensure that each resource is closed
at the end of statement?
Response:
Response:
public abstract boolean isValid();
public boolean isValid();
protected boolean isValid();
boolean isValid();
Score 1.00 of 1
Question:
If a class inheriting an abstract class does not define all of its
function then it will be known as ______.
Response:
Abstract
A simple class
Static class
interface
Score 1.00 of 1
Question:
What will be the output of the following Java code?
class ThreadDemo{ public static void main(String args[])
{ Thread t = Thread.currentThread();
System.out.println(t); } }
Response:
Thread[5,main]
Thread[main,5]
Thread[main,0]
Thread[main,5,main]
Question Results
Score 1.00 of 1
Question:
try { int number = Integer.parseInt("two"); }Which could be used to
create an appropriate catch block?
Response:
ClassCastException
IllegalStateException
NumberFormatException
None of the above is 'True
Score 1.00 of 1
Question:
Which of the following methods of the File class will delete a
directory or file?
Response:
The file class does not allow you to delete a file or directory
remove()
delete()
deleteFile()
Score 1.00 of 1
Question:
class GenericsDemo{ T data; public GenericsDemo(T data) { this.data =
data; }}
Which of the given statement is 'True about above code?
Response:
GenericsDemo object can be created by passing any type of parameter+B22:C24
GenericsDemo object can be created as given belowGenericsDemo<String>obj
= new GenericsDemo<String>();
GenericsDemo object can be created as given belowGenericsDemo<String>obj
= new GenericsDemo<String>("xyz");
Can not create object of given class
Score 1.00 of 1
Question:
When the JVM runs out of memory, which exception will be thrown?
Response:
MemoryBoundException
OutOfMemoryError
OutOfMemoryException
OutOfRangeException
Score 1.00 of 1
Question:
What will be the output of the following Java program?
public class FileDemo { public static void main(String[] args) {
String obj = "abcdef"; int length = obj.length(); char c[] = new
char[length]; obj.getChars(0, length, c, 0); CharArrayReader input1
= new CharArrayReader(c); CharArrayReader input2 = new
CharArrayReader(c, 0, 3); int i; try { while ((i = input2.read())
!= -1) { System.out.print((char) i); } } catch (IOException e) {
e.printStackTrace(); } }}
Response:
abc
abcd
abcde
Compilation fails
Score 1.00 of 1
Question:
Which among the following Sets maintains insertion order?
Response:
HashSet
TreeSet
LinkedHashSet
Both B & C
Score 1.00 of 1
Question:
What will be the output of below code?
class Test{ public static void main(String[] args) { try { int a[]=
{1, 2, 3, 4}; for (int i = 1; i <= 4; i++) { System.out.println
("a[" + i + "]=" + a[i] + "n"); } } catch (Exception e) {
System.out.println ("error = " + e); } catch
(ArrayIndexOutOfBoundsException e) { System.out.println
("ArrayIndexOutOfBoundsException"); } }}
Response:
Compiler error
Run time error
ArrayIndexOutOfBoundsException
a[1]=2na[2]=3na[3]=4n
Score 1.00 of 1
Question:
import java.util.*;
class Test {
public static void main(String[] args) {
// insert code here
obj.add("one");
obj.add("two");
obj.add("TWO");
System.out.println(x.poll());
}
}
Which, inserted at // insert code here, will compile?
Response:
List<String> obj = new LinkedList<String> ();
TreeSet<String> obj = new TreeSet<String> ();
HashSet<String> obj = new HashSet<String> ();
Queue<String> obj= new PriorityQueue<String> ();
Score 1.00 of 1
Question:
A programmer has an algorithm that requires a java.util.List that
provides an efficient implementation of add(0,object), but does NOT
need to support quick random access. What supports these requirements?
Response:
ArrayList
Queue
Linear List
LinkedList
Score 1.00 of 1
Question:
Which of the given statement will ensure that each resource is closed
at the end of statement?
Response:
Response:
[null, 1, 1, null]
[1,null]
[null,1,null]
[1,1,null]
Score 1.00 of 1
Question:
Response:
//line 1class DemoCmp implements Comparable//line
2public int compareTo(Object obj){return number-
obj.number;}
//line 1class DemoCmp implements Comparator//line
2public int compare(Object obj1,Object obj2){return
obj1.number-obj2.number;}
//line 1class DemoCmp implements Comparable//line
2public int compare(Object obj1,Object obj2){return
obj1.number-obj2.number;}
//line 1class DemoCmp implements Comparator//line
2public int compareTo(Object obj){return number-
obj1.number;}
Score 1.00 of 1
Question:
Consider the following code:
interface MyInterface {// Method declaration code }
Which of the following code snippet shows the wrong way to declare
Method in interface?
Response:
public abstract boolean isValid();
public boolean isValid();
protected boolean isValid();
boolean isValid();
Score 1.00 of 1
Question:
What will happen after the execution of below code?
public class HashSetTest { public static void main(String[] args) {
Map map = new HashMap(); map.put(new String("a"), "Audi");
map.put(new String("a"), "Ferrari"); System.out.println(map); }}
Response:
{a=Ferrari}
{a=Audi}
{a=Audi,a=Ferrari}
{a=Ferrari,a=Audi}
compilation fails
Score 1.00 of 1
Question:
Which of the following I/O classes helps you in persistence storage of
Objects?
Response:
ObjectOutputStream
DataOutputStream
FileWriter
ObjectWriter
Score 1.00 of 1
Question:
If a class inheriting an abstract class does not define all of its
function then it will be known as ______.
Response:
Abstract
A simple class
Static class
interface
Score 1.00 of 1
Question:
What is the output of the following program?
class Test {public static void main(String[] args) {try
{doMath(5);System.out.print("hi");}finally { System.out.println(" from
finally"); }}public static void doMath(int den) {int num = 7 / den;}}
Response:
hi from finally
hifrom finally
prints hi from finally 2 times
None of the above
Score 1.00 of 1
Question:
Which of these values is returned by read() method is end of file (EOF)
is encountered?
Response:
1
-1
Null
Score 1.00 of 1
Question:
Predict the output of following Java program:
class Test extends Exception { } class Main { public static void
main(String args[]) { try { throw new Test(); }
catch(Test t) { System.out.println("Got the Test Exception");
} finally { System.out.println("Inside finally block ");
} }}}
Response:
join() method
sleep() method
wait() method
run() method
Score 1.00 of 1
Question:
What will be the output of following program?
public class Foo { public static void main(String[] args) {
try { return; } finally {
System.out.println( "Finally" ); } } }
Response:
Finally
Compilatation fails
No output
Runtime Exception
Score 1.00 of 1
Question:
What is the output of the following?
import java.util.*;public class Test {public static void main(String[]
args) { Set set = new TreeSet(); set.add("anu"); set.add("anil");
set.add("sunil"); for(Object str:set){ System.out.print(str + " ");}}}
Response:
Response:
1
2
3
4
Score 1.00 of 1
Question:
Predict the output of the following program:
abstract class demo { public int a; demo() { a = 10; } abstract
public void set(); abstract final public void get();}class Test extends
demo { public void set(int a) { this.a = a; } final public void get()
{ System.out.println("a = " + a); } public static void main(String[]
args) { Test obj = new Test(); obj.set(20); obj.get(); }}
Response:
a = 10
a = 20
compilation error
runtime error
Score 1.00 of 1
Question:
What will be the output of the following Java code?
public class ThreadDemo { public static void main(String args[]) {
Thread t = Thread.currentThread();
System.out.println(t.getPriority()); }}
Response:
1
10
5
undefined
Score 1.00 of 1
Question:
What will be the output of the following Java program?
public class FileDemo { public static void main(String[] args) throws
IOException { InputStream obj = new
FileInputStream("src/inputoutput.txt");
System.out.print(obj.available()); }}
Note: inputoutput.txt is stored in the disk.
Response:
'True
'False
prints number of bytes in file
prints number of characters in the file
Score 1.00 of 1
Question:
What state does Thread enter in when it has been created and started?
Response:
new
runnable
running
waiting
Score 1.00 of 1
Question:
Which of these exception is thrown in cases when the file specified for
writing is not found?
Response:
IOException
FileException
FileNotFoundException
FileInputException
Score 1.00 of 1
Question:
Predict the output of following Java program:
class Main { public static void main(String args[]) { try {
throw 10; } catch(int e) { System.out.println("Got
the Exception " + e); } }}
Response:
Got the Exception 10
Got the Exception 0
Compilation fails
None of the above
Score 1.00 of 1
Question:
What will be the output of the following Java code?
class ThreadDemo{ public static void main(String args[])
{ Thread t = Thread.currentThread();
System.out.println(t); } }
Response:
Thread[5,main]
Thread[main,5]
Thread[main,0]
Thread[main,5,main]
Score 1.00 of 1
Question:
Which of the following is 'False about abstract classes in Java?
Response:
we can use both static and non static variables in abstract classes
Abstract classes can have constructors
A class can be made abstract without any abstract method
A class can inherit from multiple abstract classes
Score 1.00 of 1
Question:
What will be the output?
interface A{ public void method();}class One{ public void method(){
System.out.println("Class One method"); }}class Two extends One
implements A{ public void method(){ System.out.println("Class Two
method"); }}public class Test extends Two{ public static void
main(String[] args){ A a = new Two(); a.method(); }}
Response:
will print Class One method
will print Class Two method
compiles fine but print nothing
Compilation Error
Score 1.00 of 1
Question:
A _______ is used to walk through a collection and can remove elements
from the collection during the iteration.
Response:
Enumeration
Iterator
ArrayList
Vector
Score 1.00 of 1
Question:
What will happen after the execution of below code?
class CreateObject{public static void main(String []args){Set set = new
TreeSet();set.add("Priya");set.add("Ritu");set.add(100);}}
Response:
All elements will be successfully added to set
last element 100 will not be added to set
ClassCastException
IlleagalStateException
Question Results
Score 1.00 of 1
Question:
Which method can be used to check null on an Optional variable in Java
8
Response:
isPresent()
isNullable()
isPresentable()
isNotNull()
Score 1.00 of 1
Question:
How sorting speed has been improved significantly on multi-core
machines by using -
Response:
Arrays.parallelSort
Arrays.sort
Collection.parallelSort
Arrays.sortParallelly
Score 1.00 of 1
Question:
In java 8, R apply(T t) is a method of-
Response:
Function
Process
Predicate
None
Score 1.00 of 1
Question:
How can we obtain source of objects in java 8?
Response:
Stream stream()
Stream obtain()
Stream obtain Source()
All
Score 1.00 of 1
Question:
A pipeline is a sequence of what operations in java 8
Response:
multi-threading
concurrent
consequent
stream
Score 1.00 of 1
Question:
Which class can be used Instead of System.getCurrentTimeMillis() to get
a date and time in Java 8 -
Response:
Clock
Date
Time
Timer
Score 1.00 of 1
Question:
What is Predicate in Java 8 -
Response:
method
class
Interface
Framework
Score 1.00 of 1
Question:
Lambda expressions are __________ scoped
Response:
Lexically
Semantically
Binary
None
Score 1.00 of 1
Question:
Which package contains Date/Time (JSR 310) API in Java 8 -
Response:
java.time
java.util.time
java.timedate
java.util.calendar
Score 1.00 of 1
Question:
Which is aggregate operation in Java 8
Response:
filter
map
forEach
All
Score 1.00 of 1
Question:
Which of these does Streamfilter() operates on
Response:
Predicate
Interface
Class
Methods
Score 1.00 of 1
Question:
In Java 8 Interfaces, methods can be:
Response:
default
abstract
all
none
Score 1.00 of 1
Question:
code before Java 8 essentially used to be -
Response:
Declarative
Imperative
Subjective
None
Score 1.00 of 1
Question:
PermGen space has been replaced with which of these in Java 8 -
Response:
PermSpace
PermSpaceGen
Metaspace
MetaGenSpace
Score 1.00 of 1
Question:
We need to override which Predicate method in Java 8 -
Response:
predict(T t)
predictable(T t)
testable(T t)
test(T t)
Score 1.00 of 1
Question:
Nashorn the new JavaScript engine is an implementation of -
Response:
javax.engine.Engine
javax.script.Engine
javax.javaScript.Engine
javax.script.ScriptEngine
Score 1.00 of 1
Question:
Which of these does Streammap() operates on
Response:
Class
Interface
Predicate
Function
Score 1.00 of 1
Question:
In java 8 Function is ?
Response:
Class
Interface
Lambda Expression
Object
Score 1.00 of 1
Question:
Stream operations in java 8 can be divided into
Response:
Terminal types
Intermediate types
All
None
Score 1.00 of 1
Question:
Which of these represents a process that accepts one argument and
produces a result in Java 8
Response:
Function
Process
Method
JavaFunctions
Score 1.00 of 1
Question:
On which of these does annotations can be used on in Java 8
Response:
Local variables
Super classes
Generic types
All of these
Score 1.00 of 1
Question:
Which is new command line tool for the Nashhorn JavaScript engine in
java 8 -
Response:
jcs
jfs
jjs
jss
Score 1.00 of 1
Question:
void accept(T t) is method of -
Response:
Consumer
Producer
Both
None
Score 1.00 of 1
Question:
What can help us in avoiding NullPointeExceptions and null checks in
java 8 -
Response:
Optional
Required
NotNull
NotRequired
Score 1.00 of 1
Question:
Example of functional interfaces in Java 8 -
Response:
java.util.concurrent.Callable
java.lang.Runnable
All
None
Score 1.00 of 1
Question:
Which of these does forEach() operates on
Response:
Methods
Consumer
Producer
Predicate
Score 1.00 of 1
Question:
The Java 8 API with a sequence of elements which of these supports
sequential and parallel aggregate operations -
Response:
Hadoop
Streams
SequenceProgramming
Big-data
Score 1.00 of 1
Question:
Which of these should be used to show package-level and class-level
dependencies of Class files in Java 8
Response:
dep
ideps
jdep
jdeps
Score 1.00 of 1
Question:
Predicate is in which package in Java 8
Response:
java.util.predicate
java.util.object
java.util.objects
java.util.predict
Question Results
Score 1.00 of 1
Question:
Which Spring Framework module is used to implement cross-cutting
concerns in Spring based-applications?
Response:
ORM
AOP
JDBC
TXM
Score 1.00 of 1
Question:
What is the primary use of the Spring Security module?
Response:
void
any
any[]
unknown
Score 1.00 of 1
Question:
Different ways to inject Spring beans in Spring-based applications?
Response:
Constructor based
Setter based
Field-based
All of the above
Score 1.00 of 1
Question:
What is the scope to create a new instance every time the bean is
requested from the spring container?
Response:
singleton
prototype
request
session
Score 1.00 of 1
Question:
Which is the front controller in Spring MVC?
Response:
FrontDispatcherServlet
DispatcherServlet
FrontControllerService
None of the above
Score 1.00 of 1
Question:
Which interface represents the Spring IOC container?
Response:
ApplicationContext
ApplicationContentFactory
SessionFactory
DispatchServlet
Score 1.00 of 1
Question:
Definitely Typed is_____
Response:
a superset of TypeScript
the official name of TypeScript
a project whose goal is to make types dynamic
a project that provides a central repository of TypeScript definitions for NPM
packages which do not have types
Score 1.00 of 1
Question:
Spring MVC Framework is designed based on which Design Pattern?
Response:
Model-View-Controller (MVC)
Layered pattern
Client-server pattern
None of the above
Score 1.00 of 1
Question:
What is the default scope of the Spring Bean?
Response:
singleton
prototype
request
session
Score 1.00 of 1
Question:
Extension of typescript is?
Response:
.d.tp
d.td
.d.ts
.d.ty
Score 1.00 of 1
Question:
What are Spring stereotype annotations?
Response:
Using Getter and Setter methods
Using Setter and Constructor
Using Getter and Constructor
Using Setter and Factory methods
Score 1.00 of 1
Question:
JdbcTemplate implements the below design pattern?
Response:
Strategy design pattern
Template Design pattern
Singleton design pattern
Decorator design pattern
Score 1.00 of 1
Question:
You can disable implicit variable type assignment by enabling the
compiler option:
Response:
noImplicitAny
noAutoType
Implicit = FALSE
autoTypeAssignment = FALSE
Score 1.00 of 1
Question:
TypeScript supports Object Oriented Programming concepts like classes,
interfaces, inheritance.
Response:
TRUE
False
Can be true or false
None of the above
Score 1.00 of 1
Question:
What is the purpose of the Spring MVC module?
Response:
DispatcherServlet
Controller
HandlerMapper
None of the above
Score 1.00 of 1
Question:
Are singleton beans thread-safe?
Response:
Yes
No
Score 1.00 of 1
Question:
What is the purpose of the Spring MVC module?
Response:
ViewResolver
Handler Mapper
Controller
Model
Score 1.00 of 1
Question:
Definitely Typed is_____
Response:
a superset of TypeScript
the official name of TypeScript
a project whose goal is to make types dynamic
a project that provides a central repository of TypeScript definitions for NPM
packages which do not have types
Question Results
Score 1.00 of 1
Question:
Select the correct statement to create ResultSet interface Object:
Response:
PreparedStatement stmt =
connection.prepareStatement(String sql);ResultSet rs =
new ResultSet();
PreparedStatement stmt =
connection.prepareStatement(String sql);ResultSet rs =
stmt.executeQuery();
PreparedStatement stmt = new PrepareStatement(String
sql);ResultSet rs = stmt.executeQuery();
PreparedStatement stmt = new
PrepareStatement();ResultSet rs =
stmt.executeQuery(String sql);
Score 1.00 of 1
Question:
Which of the given is the correct implementation of Test suites?
Response:
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith
@Suite.SuiteClasses({ TestCalAdd.class,
TestCalSubtract.class,
TestCalMultiply.class, TestCalDivide.class })
public class CalSuite {
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({ TestCalAdd.class,
TestCalSubtract.class,
TestCalMultiply.class, TestCalDivide.class })
public class CalSuite {
}
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@Run(Suite.class)
@Suite.SuiteClasses({ TestCalAdd.class,
TestCalSubtract.class,
TestCalMultiply.class, TestCalDivide.class })
public class CalSuite {
// the class remains completely empty,
// being used only as a holder for the above
annotations
}
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@Suite.SuiteClasses({ TestCalAdd.class,
TestCalSubtract.class,
TestCalMultiply.class, TestCalDivide.class })
public class CalSuite {
// the class remains completely empty,
// being used only as a holder for the above
annotations
}
Score 1.00 of 1
Question:
Response:
try {
conn.setAutoCommit('True);
// perform transactions
conn.commit();
con.setAutoCommit('False);
} catch (SQLException e) {
conn .rollback() ;
}
Response:
rs.getString(0)
rs.getString(1)
rs.getString("name")
None of the above
Score 1.00 of 1
Question:
Which driver is called as thin-driver in JDBC?
Response:
Type-4 driver
Type-1 driver
Type-3 driver
Type-2 driver
Score 1.00 of 1
Question:
Select the output of the given code:
public class ForEachExample { public static void main(String[] args) {
List<String> gamesList = new ArrayList<String>();
gamesList.add("Football"); gamesList.add("Cricket");
gamesList.add("Chess"); gamesList.add("Hocky");
gamesList.add("Cricket"); gamesList.add("Chess");
gamesList.add("Football"); gamesList.add("null");
gamesList.add(null); Set<String> set =
gamesList.stream().collect(Collectors.toSet()); set.forEach(game ->
System.out.println(game)); }}
Response:
ChessHockynullCricketnullFootball
ChessHockynullCricketFootball
FootballCricketChessHockyCricketChessFootballnull
FootballCricketChessHockyCricketChessFootballnullnull
Score 1.00 of 1
Question:
What will be the output of the given program?
class Test implements Runnable { public void run() {
System.out.println("Run"); } } class Myclass { public static void
main(String[] args) { Test t = new Test(); t.start();
System.out.println("Main"); } }
Response:
Main Run
Run Main
Compile time error
Depend upon JVM
Score 1.00 of 1
Question:
What will be the output of the given program?
class MyThread extends Thread { @Override public void run() {
System.out.println("child thread"); }}public class ThreadDemo { public
static void main(String args[]) { MyThread thread = new MyThread();
thread.start(); thread.start(); }}
Response:
Response:
Run
Main
Compile time error
Run Main
Score 1.00 of 1
Question:
Select the correct statement to create a thread pool 6of 5 fixed
thread:
Response:
ExecutorService executor = Executors.newThreadPool(5);
ExecutorService executor =
Executors.newFixedThreadPool(5);
ExecutorService executor = new ExecutorService(5);
ExecutorService executor = new ThreadPoll(5);
Score 1.00 of 1
Question:
What are the two types of Streams offered by java 8?
Response:
Response:
Main Run
Run Main
Depend upon Program
Depend upon JVM
Score 1.00 of 1
Question:
What is the output of the given code?
class Employee { int id; String name; public Employee() { } public
Employee(int id, String name) { this.id = id; this.name = name; }
//setters and getters}public class ComparableTest { public static void
main(String[] args) { List<Employee> list = new ArrayList<>();
list.add(new Employee(123, "Sugan")); list.add(new Employee(101,
"Kavita")); list.add(new Employee(132, "Anju")); Comparator<Employee>
comparator = (a, b) -> { return a.getName().compareTo(b.getName());
}; list.sort(comparator); list.forEach(e ->
System.out.println(e.getName())); }}
Response:
SuganKavitaAnju
AnjuKavitaSugan
KavitaSuganAnju
Compilation fails
Score 1.00 of 1
Question:
What is the output of the givne code?
public class ForEachExample { public static void main(String[] args) {
List<String> trainers = new ArrayList<String>();
trainers.add("Soham"); trainers.add("Tina"); trainers.add("Anju");
trainers.add("Kavya"); trainers.add(null); trainers.add("null");
trainers.add("Soham"); trainers.add("Tina"); Set<String> list =
trainers.stream().filter(s ->
s.startsWith("S")).collect(Collectors.toSet());
System.out.println(list); }}
Response:
[Tina,Soham,null]
[Soham,Tina,Soham,Tina]
[Soham, Tina]
Compilation fails
NullPoinerException
Score 1.00 of 1
Question:
Select the correct code to display the message "Good Luck":
Response:
'interface MyLambda { public String test();}public
class LambdasTest { public static void main(String[]
args) { MyLambda my = () -> { return "Good Luck";
}; System.out.println(my.test()); }}
'interface MyLambda { public String test();}public
class LambdasTest { public static void main(String[]
args) { MyLambda my = (String s) -> { return "Good
Luck"; }; System.out.println(my.test()); }}
interface MyLambda { public String test();}public
class LambdasTest { public static void main(String[]
args) { MyLambda my = () -> { return "Good Luck";
} System.out.println(my.test()); }}
interface MyLambda { public String test();}public
class LambdasTest { public static void main(String[]
args) { MyLambda my = () -> { return "Good Luck";
}; my.test(); }}
Score 1.00 of 1
Question:
In java 8, void accept(T t) is a method of:
Response:
Predicate
Supplier
Function
Consumer
Score 1.00 of 1
Question:
In java 8, R apply(T t) is a method of:
Response:
Function
Process
Predicate
Consumer
Score 1.00 of 1
Question:
JUnit is used for _________ in Java Application.
Response:
Integration Testing
Code Review
Unit Testing
Black Box Testing
Score 1.00 of 1
Question:
Which of the given annotation is used to do initialization of some task
before each test run?
Response:
@Test
@After
@BeforeClass
@Before
Score 1.00 of 1
Question:
Which of the given option is correct for adding exception to the test
method given below?
Public void divideByZeroTest(){calobj.divide(15,0);}
Note : calobj is an object of Calculate class which contains divide(int
x,int y) method.
Response:
@Test(expected = ArithmeticException.class)
@Test( ArithmeticException.class)
@Before( ArithmeticException.class)
@Before(expected = ArithmeticException.class)
Score 1.00 of 1
Question:
Consider the following code snippet:
import static org.junit.Assert.assertEquals;import org.junit.Test;class
Calculator { public long add(long number1, long number2) { return
number1 + number2; }}public class CalculatorTest { @Test public void
add() throws Exception { Calculator cal = new Calculator();
assertEqual(4, cal.add(1, 3)); }}
The above code returns compile time error. What change needs to be done
in order to run the test successfully?
Response:
There is no error in the code above
The TestCase class has not been extended hence it not recognized as a Test class
Change the assertEquals method to assert'True(4,cal.add(1,3))
The assertEqual method should be written as assertEquals (4,cal.add(1,3))
Question Results
Score 1.00 of 1
Question:
What will be the value of sum after the while loop? int j=9; int sum =
0; while (j<10) { sum += j ; j++; }
Response:
0
9
10
19
Score 0.00 of 1
Question:
Corrective maintenance activity in code construction comes after ______
activity
Response:
System testing
Problem definition
Coding and debugging
System integration
Score 1.00 of 1
Question:
What will be optimized version of this loop?sum = 0;for (i=1; i<=N;
i++) sum = sum + i * j / k + 10;
Response:
sum = 0;for (i=1; i<=N; i++) sum = sum + i * (j / k) + 10;
sum = 0;m = j / k;for (i=1; i<=N; i++) sum = sum + i * m + 10;
sum = (j / k) + 10;for (i=1; i<=N; i++) sum = sum + i * m + 10;
sum = 0;m = j / k + 10;for (i=1; i<=N; i++) sum = sum + i * m;
Score 0.00 of 1
Question:
Worst case scenario in sorting an array of 10 elements using Bubble
sort would be ___ operations.
Response:
log 10
10
20
100
Score 1.00 of 1
Question:
What type of loop would you use in these cases?i. No. of times to loop
is unknown initiallyii. No. of times to loop is known initiallyiii.
loop body needs to be executed at least once
Response:
i - while, ii - for, iii - for
i - while, ii - while, iii - for
i - while, ii - for, iii - do..while
"for" loop for all
Score 1.00 of 1
Question:
Put these steps of building a program, in a correct sequence.i. Check
the designii. Check the codeiii. Code the programiv. Design the program
Response:
i,ii, iii, iv
ii, iii, iv, i
iv, i,iii, ii
iv, iii, i,ii
Score 0.00 of 1
Question:
It is better to use more number of global variables as they can be
easily accessed from different routines.
Response:
TRUE
FALSE
Score 1.00 of 1
Question:
Which among the following is a good code layout?
Response:
TRUE
FALSE
Score 1.00 of 1
Question:
Which of these data structures can be used for sorting purpose?
Response:
Graph
Linked list
Tree
Circular queue
Score 0.00 of 1
Question:
Which program might run faster?
Response:
for (i=0; i<5; i++) strarr[i] = "NULL";
for (i=0; i<4; i++) strarr[i] = "NULL"; strarr[4] = "NULL";
strarr[0] = "NULL";for (i=1; i<5; i++) strarr[i] = "NULL";
strarr[0] = "NULL";strarr[1] = "NULL";strarr[2] = "NULL";strarr[3] =
"NULL";strarr[4] = "NULL";
Score 1.00 of 1
Question:
How can this following search algorithm improved further?for (i=0;
i<count; i++) { if (a[i] == item) { found=true; } }
Response:
By reducing the value of count variable
By changing the data type of array a
By inserting a 'break' statement after 'found=true' within 'if'
By inserting a 'break' statement after 'found=true' after 'if'
Score 1.00 of 1
Question:
Data types of variables cannot determine
Response:
Type of data that can be stored
Amount of memory a variable occupies
Address where the variable can be stored in memory
The range of data that can be stored
Score 1.00 of 1
Question:
Ideal data type to indicate customer's gender i.e. either Male or
Female is
Response:
Integer
Floating poing number
String array
Character
Score 1.00 of 1
Question:
Which of the following statements would fit in the blank space below in
this searching loop?for (i = 0; i < N; i++){ if (arr[i] == item){ found
= true; ____________ }}
Response:
continue
return
exit
break
Score 1.00 of 1
Question:
What's wrong with following program segment?const int Pi = 3.14;float
area = 0, rad = 5;Pi = 6.28;area = Pi * rad * rad;
Response:
'area' should be declared as 'int'
Value of 'Pi' cannot be changed
'Pi' should be assigned to 3.14 again
Area calculation method is wrong
Score 1.00 of 1
Question:
What is the equivalent 'jammed loop' version for the following code?
for (i=0; i<10; i++) sum1 = sum1 + i; for (i=0; i<20; i++) sum2 = sum2
+ i;
Response:
for (i=0; i<10; i++) { sum1 = sum1 + i; sum2 = sum2 + i;}
for (i=0; i<20; i++) { sum1 = sum1 + i; sum2 = sum2 + i;}
for (i=0; i<10; i++) { sum1 = sum1 + i; sum2 = sum2 + i;} for (i=10; i<20; i++)
{ sum2 = sum2 + i;}
These loops cannot be jammed
Score 0.00 of 1
Question:
The OS maintains a _____ data structure to keep the processes that are
to be executed next in line.
Response:
Linked list
Stack
Graph
Queue
Score 1.00 of 1
Question:
One has to think about efficiency of the program: i. While designing
itii. While constructing it
Response:
Only i.
Only ii.
Both i & ii
Neither i nor ii
Score 0.00 of 1
Question:
What is the output of following program segment?int option = 2;switch
(option) { case 1: printf("One"); case 2: printf("Two"); case 3:
printf("Three"); }
Response:
One
Two
TwoThree
Three
Score 1.00 of 1
Question:
Consider the array defined below:int phoneno[5];Which one of the
following assignment is wrong?
Response:
phoneno[1] = 1111;
phoneno[2] = 2222;
phoneno[2] = -2222;
phoneno[5] = 5555;
Score 1.00 of 1
Question:
Which is the best way to make the loop exit in the middle?
Response:
use goto statement
use break statement
use return statement
use recursion
Score 1.00 of 1
Question:
How many times the loop will get executed?for (j=1; j>10; j++) sum =
sum + i;
Response:
0
1
9
10
Score 1.00 of 1
Question:
Which among the following is an example of a program statement?i.
a=0;ii. a + - b;iii. -b + a = a + b;
Response:
i only
ii only
ii & iii only
All are correct
Score 1.00 of 1
Question:
What will be printed if the value of x=20?if (x>10 AND x<20) print
HIGHelse print LOW
Response:
HIGH
LOW
HIGHLOW
Nothing gets printed
Question Results
Score 0.00 of 1
Question:
Given:
public class Main { float result; public static void main(String[]
args) { result = 5 / 2; System.out.println(result); }}
What will be the output?
Response:
2
2.0
2.5
Compile time error
Score 1.00 of 1
Question:
Analyze the following code and choose the correct answer:
int[] arr = new int[5];arr = new int[6];
Response:
The code has compile errors because the variable arr cannot be changed once it
is assigned.
The code has runtime errors because the variable arr cannot be changed once it
is assigned.
The code can compile and run fine. The second line assigns a new array to arr.
The code has compile errors because we cannot assign a different size array to
arr.
Score 0.00 of 1
Question:
What is 'True about the following code?
enum EnumDemo { A }class Test { enum EnumD { B } void
my_method() { enum EnumC { D } } }
Response:
The code compiles without any error
The code compiles if we remove line number 1
The code compiles if we remove line number 5
None of the above is correct
Score 1.00 of 1
Question:
Which of the following are Object class methods?
Response:
toString()
equals()
hashCode()
All of the above
Score 1.00 of 1
Question:
What will happen when you attempt to compile and run the following
class?
class Base { Base(int var) { System.out.println("Base"); }}class
Derived extends Base { public static void main(String argv[]) {
Derived obj = new Derived(); }}
Response:
Compiles without any problem
Compiles and produces output "Base"
Generates Compile time error
None of the above
Score 1.00 of 1
Question:
public class Demos { public static void main(String[] args)
{ String input = "Hello Welcome"; String pattern =
"\\sHello\\sWelcome\\s"; boolean flag = Pattern.matches(pattern,
input); System.out.println(flag);}}
What will be the result?
Response:
'True
'False
Compilation error
Exception
Score 0.00 of 1
Question:
class Employee{String name;int id;public Employee(String name,int
id){this.name = name;this.id=id;}}public class Manager extends
Employee{public static void main(String []args){Manager mgr = new
Manager();}}What will happen after execution of above code?
Response:
Manager class object will be successfully created
Compile time error as there is no default constructor in class Employee
Manager object will be successfully created after implementing default
constructor in Manager class
Default constructor need to be implemented in both classes for successful
creation of Manager class object
Score 1.00 of 1
Question:
What will be the output of the following code snippet?
String str1 = new String( "hello" );String str2 = "hello"; if
(str1==str2) System.out.println( "Equals"); else
System.out.println( "Not Equal");
Response:
Equal
Not Equal
Compilation error
None of the above
Score 1.00 of 1
Question:
class Shape{final public double calArea(){}}public class Circle extends
Shape{int radius;public Circle(int radius){this.radius = radius;}public
double calArea(){return 3.142*radius*radius;}public static void
main(String []args){Shape obj = new
Circle(5);System.out.println(obj.calArea());}}
What will be the output of above code?
Response:
It will display area of circle with radius 5
no output
compilation error
runtime Exception
Score 1.00 of 1
Question:
Which of the following statements are 'True?
Response:
No arg constructor is allways supplied by the Compiler
Constructors cannot be overloaded
Constructors cannot have return type.
Constructors can be static
Score 1.00 of 1
Question:
What will be the output after compiling and running following code?
public class Test{ public static void main(String[] args){
int a=5 , b=6, c=7; System.out.println("Value is "+ b + c);
System.out.println(a + b + c); System.out.println("String "
+ (b+c)); }}
Response:
Value is 67 18 String 13
Value is 13 18 String 13
Value is 13 18 String
Compilation fails
Score 1.00 of 1
Question:
What is the output of the given code?
public class Test {
public static void main(String args[]) {
final int i;
i = 20;
System.out.println(i);
}
}
Response:
20
compile time error
runtime error
0
Score 1.00 of 1
Question:
Given :
public class Test {
public static void main(String args[]) {
int x = 12;
while (x <10) {
x--;
}
System.out.print(x); //line 7
}
}
Response:
6
7
10
Compile time error
Score 1.00 of 1
Question:
What all gets printed when the following code is compiled and run?
public class test { public static void main(String args[]) {
for(int i = 0; i <2; i++) { for(int j = 2; j>= 0; j--) {
if(i == j) break; System.out.println("i=" + i + " j="+j);
} } }}
1. i=0 j=0 2. i=0 j=1 3. i=0 j=2 4. i=1 j=0 5. i=1 j=1 6. i=1 j=2
Response:
'1,3,5
'2,4,6
'1,2,5
'3,2,6
Score 1.00 of 1
Question:
What is the output of the given code?
class SuperClass {
int b = 10;
}
Response:
10
20
Compilation fails
0
Score 1.00 of 1
Question:
Given the following code fragment: XXXX choice ; // variable choice is
declared and initialized here switch( choice ) { case 100 :
System.out.println("One hundred");break ; case 20 :
System.out.println("Twenty");break ; case 30 :
System.out.println("Thirty");break ; }Choose the declarations of choice
which will not cause a compiler error:
Response:
byte choice = 100 ;
short choice = 100 ;
int choice = 300 ;
All of the above
Score 1.00 of 1
Question:
Memory deallocation in java is done by:
Response:
Programmer
Operating system
Garbage collector
None of the above
Score 1.00 of 1
Question:
Automatic type conversion in Java takes place when:
Response:
Two type are compatible and size of destination type is shorter than source type.
Two type are compatible and size of destination type is equal of source type.
Two type are compatible and size of destination type is larger than source type.
All of the above
Score 1.00 of 1
Question:
class Shape{Shape(){}}public class Triangle extends Shape{int
base,height;public Triangle(int base,int height){this.base =
base;this.height=height;}public double calArea(){return
o.5*base*height;}public static void main(String []args){Shape ref = new
Triangle(3,4);System.out.println(ref.calArea());}
Which change need to be done in the Shape class for successful
execution of program?
Response:
Declare Shape as abstract class
Remove default constructor from Shape class
declare abstract double calArea() in Shape class
declare abstract double calArea() in Shape class and declare Shape class as
abstract class
Score 1.00 of 1
Question:
Integer var1 = new Integer(2); Integer var2 = new Integer(2); What
happens when you do if (var1==var2)?
Response:
'True
'False
Compilation error
Runtime Exception
Score 1.00 of 1
Question:
public class RegexMatches{ private static String regex = "dog";
private static String input = "The dog says meow. " +"All dogs say
meow."; private static String replace = "cat"; public static void
main(String[] args) { //line no.1 Matcher m =
p.matcher(input); INPUT = m.replaceAll(replace);
System.out.println(input); }}
Which code need to be inserted at line no.1 to execute it successfully?
Response:
Pattern p = Pattern.compile(regex);
Pattern p = Pattern.test(regex);
Pattern p = Pattern.matches(regex);
Pattern p = new Pattern(regex);
Score 1.00 of 1
Question:
Which of the given LocalDate class method is used to obtain current
date?
Response:
now()
parse()
format()
newInstance()
Score 1.00 of 1
Question:
Which one of the following is a valid statement?
Response:
'char[] c = new char();
'char[] c = new char[5];
char[] c = new char(4);
char[] c = new char[];
Score 1.00 of 1
Question:
This always will points to:
Response:
Response:
m1 calledm2 called
m1 calledm1 calledm2 called
Compilation fails
Runtime error
Score 1.00 of 1
Question:
State 'True or 'False:You can't use a Java keyword as an identifier.
Response:
'True
'False
Score 1.00 of 1
Question:
When access modifier is omitted from the definition of the member of a
class. The member has _________ access.
Response:
default
public
private
protected
Score 1.00 of 1
Question:
Consider the following code:
interface Greek { } class Alpha implements Greek { } class Beta extends
Alpha {} class Delta extends Beta { public static void main(
String[] args ) { Beta obj = new Beta(); // insert code
here } }
Which of the following code snippet when inserted individual at the
commented line (// insert code here), will cause a
java.lang.ClassCastException?
Response:
Greek objGrk = (Beta)(Alpha)obj;
Alpha objAlpha = obj;
Greek objGrk = (Alpha)obj;
Beta objBeta = (Beta)(Alpha)obj;
Greek objGrk = (Delta)obj;
Score 1.00 of 1
Question:
What will be the output after compiling and running following code?
public class Test{ public static void main(String args[]){
int x =5; x *= 3 + 7; System.out.println(x); }}
Response:
22
50
10
Compilation fails
Score 1.00 of 1
Question:
State 'True or 'False:We can use this in static methods.
Response:
'True
'False
Score 1.00 of 1
Question:
public class test {
static void methodA(short s) {
System.out.println("methodA(short) called");
}
static void methodA(int i) {
System.out.println("methodA(int) called");
}
static void methodB(float f) {
System.out.println("methodB(float) called");
}
static void methodB(double d) {
System.out.println("methodB(double) called");
}
Response:
methodA(short) called methodB(float) called
methodA(int) called methodB(double) called
methodA(int) called methodB(float) called
Compilation fails
Score 1.00 of 1
Question:
The concept of multiple inheritance is implemented in Java by:I.
Extending two or more classes.II. Extending one class and implementing
one or more interfaces.III. Implementing two or more interfaces.
Response:
Only (II)
(I) and (II)
(II) and (III)
Only (I)
Only (III)
Score 1.00 of 1
Question:
Given:
public class Demo { //Line 1public static void main (String[] args) {
//Line 2byte var1 = 127; //Line 3byte var2 = 126; //Line 4 byte
result = var1 + var2; //Line 5}}
Which statement is 'True?
Response:
Compilation succeeds and d takes the value 253.
Line 5 contains an error that prevents compilation.
Line 5 throws an exception indicating "Out of range"
Line 3 and 4 contain errors that prevent compilation.
Score 1.00 of 1
Question:
What will be the result of compiling and running the given code?
class SuperClass { int b = 10; private SuperClass() { this.b = 7; }
int f() { return b; }}class SubClass extends SuperClass { int
b;}public class MainTest { public static void main(String[] args) {
SuperClass a = new SubClass(); System.out.println(a.f()); }}
Response:
Compilation Fails
Prints 0
Prints 10
Prints 7
Score 1.00 of 1
Question:
class Demo{}public class SubDemo extends Demo{public static void
main(String []args){Demo obj = new SubDemo();System.out.println(obj
instanceof Demo);}}
What will be the output of above code?
Response:
False
True
Demo
SubDemo
Score 1.00 of 1
Question:
What is the Regular Expression Matching Zero or More Specific
Characters?
Response:
\
$
*
^
Score 1.00 of 1
Question:
Which of the following are features of Java Programming Language?
Response:
Robust
Multithreaded
Interpreted
All of the above
Question Results
Score 1.00 of 1
Question:
Which of the following creates a List of 3 visible items and multiple
selections abled?
Response:
new List(false, 3)
new List(3, true)
new List(true, 3)
new List(3, false)
Score 1.00 of 1
Question:
What does the expression float a = 35 / 0 return?
Response:
0
Not a Number
Infinity
Run time exception
Score 1.00 of 1
Question:
Which of the following is a valid syntax to synchronize the HashMap?
Response:
Map m = hashMap.synchronizeMap();
HashMap map =hashMap.synchronizeMap();
Map m1 = Collections.synchronizedMap(hashMap);
Map m2 = Collection.synchronizeMap(hashMap);
Score 1.00 of 1
Question:
What is the default encoding for an OutputStreamWriter?
Response:
UTF-8
Default encoding of the host platform
UTF-12
None of the above
Score 1.00 of 1
Question:
What will be the output of the following program? public class Test {
public static void main(String[] args) { int count = 1; while (count <= 15) { System.out.println(count
% 2 == 1 ? "***" : "+++++"); ++count; } // end while } // end main }
Response:
15 times ***
15 times +++++
8 times *** and 7 times +++++
Both will print only once
Score 1.00 of 1
Question:
Which of the following is a valid long literal?
Response:
ABH8097
L990023
904423
0xnf029L
Score 1.00 of 1
Question:
Which option is false about the final keyword?
Response:
A final method cannot be overridden in its subclasses.
A final class cannot be extended.
A final class cannot extend other classes.
A final method can be inherited.
Score 1.00 of 1
Question:
What is the result of the following program? public static synchronized
void main(String[] args) throws InterruptedException { Thread f = new
Thread(); f.start(); System.out.print("A"); f.wait(1000);
System.out.print("B"); }
Response:
It prints A and B with a 1000 seconds delay between them
It only prints A and exits
It only prints B and exits
A will be printed, and then an exception is thrown.
Score 1.00 of 1
Question:
Which of the following is a valid declaration of a char?
Response:
char ch = '\utea';
char ca = 'tea';
char cr = \u0223;
char cc = '\itea';
Score 1.00 of 1
Question:
In character stream I/O, a single read/write operation performs _____
Response: