You are on page 1of 253

QuestionText Choice1 Choice2 Choice3 Choice4 Choice5 Grade1 Grade2 Grade3 Grade4 Grade5

A compilation
What will be the result of compiling the error will
following program? occur at (Line
public class MyClass { no 2), since
SubBank

long var; A compilation A compilation the class


public void MyClass(long param) { var = error will error will does not
param; } // (Line no 1) occur at (Line occur at (2), have a

public class Abs extends Base{

of A executes of C executes of C executes of A executes


first, followed first followed first followed first followed
by the by the by the by the
constructor of constructor of constructor of constructor of
B and C A and B B and A C and B 1 0 0 0

Compilation Compiles and Compiles but Compiles and


System.out.print(new S().roll);}} error display 1 no output diplay 0 1 0 0 0
Access public static void main(String[] args) { no 1), since since the constructor
Specifiers MyClass a, b; constructors class does that takes The program
Constructors a = new MyClass(); // (Line no 2) cannot not have a one will compile
Methods } specify a default argument of without
NewQB } return value constructor type int. errors. 0 0 0 1
Access
Specifiers
Constructors
Methods Which of the following declarations are boolean b = String s = int i = new
NewQB correct? (Choose TWO) TRUE; byte b = 256; “null”; Integer(“56”); 0 0 0.5 0.5
What will happen when you attempt to
compile and run this code?
abstract class Base{
abstract public void myfunc(); public void another(){ System.out.println("Another method");
}

}
Access public static void main(String argv[]){
Abs a = new Abs();
a.amethod(); The compiler
} The code will will complain
public void myfunc(){ compile but that the
System.out.println("My Func"); The compiler complain at method
} will complain run time that myfunc in the
Specifiers public void amethod(){ that the Base the Base base class
Constructors myfunc(); class has non class has non has no body,
Methods } abstract abstract nobody at all
NewQB } methods methods to print it 1 0 0 0

Constructor Constructor Constructor Constructor

Access class A, B and C are in multilevel inheritance


Specifiers Constructors hierarchy repectively . In the main method of some other class if class C object is created, in what sequence the three constructors execute?
Methods NewQB

Access Specifiers Consider the following code and choose the


Constructors Methods correct option:
NewQB package aj; private class S{ int roll; S(){roll=1;} }
package aj; class T
{ public static void main(String ar[]){

Here is the general syntax for method

definition:
The The
accessModifier returnType methodName( returnValue returnValue
parameterList ) can be any must be the
{ type, but will same type as
Java statements be the
automatically returnType, The
return returnValue; converted to If the or be of a returnValue
Access } returnType returnType is type that can must be
Specifiers when the void then the be converted exactly the
Constructors method returnValue to returnType same type as
Methods What is true for the returnType and the returns to the can be any without loss the
NewQB returnValue? caller type of information returnType. 0 0 1 0
Access
Specifiers A) A call to instance method can not be made
Constructors from static context.
Methods B) A call to static method can be made from Both are Both are Only A is Only B is
NewQB non static context. FALSE TRUE TRUE TRUE 0 . 0 0

Consider the following code and choose the

Access correct option:


Specifiers class A{ A(){System.out.print("From A");}} Compiles but
Constructors class B extends A{ B(int z){z=2;} throws
Methods public static void main(String args[]){ Compilation Comiples and runtime Compiles and
NewQB new B(3);}} error prints From A exception display 3 0 1 0 0

class Sample

{int a,b;
Sample()
{ a=1; b=2;
System.out.println(a+"\t"+b);
}
Sample(int x)
{ this(10,20);
a=b=x;
System.out.println(a+"\t"+b);
}
Sample(int a,int b)
{ this();
this.a=a;
this.b=b;
System.out.println(a+"\t"+b);
}
}
class This2
{ public static void main(String args[])
Access {
Specifiers Sample s1=new Sample (100);
Constructors }
Methods } 100 100 1 2 1 2 100 100 10 20 1 2 100 1 2 10 20 100
NewQB What is the Output of the Program? 10 20 10 20 100 100 0 0 0 1
Compiles and Compiles but
throw run doesn't
Compiles and time display Compilation
display Hi exception anything fails 1 0 0 0

code
code compiles but
compiles fine will not
and will display compliation j can not be
display 23 output error initialized 0 0 1 0

public class Pri extends Base{

static void print(int i, String s) {


System.out.println("int: " + i + ", String: " +
s);

Access Specifiers Consider the following code and choose the


Constructors Methods correct option:
NewQB class A{ private static void display(){ System. out.print("Hi");}
public static void main(String ar[]){
display();}}

Access Specifiers Consider the following code and choose the


Constructors Methods correct option:
NewQB package aj; class A{ protected int j; }
package bj; class B extends A
{ public static void main(String ar[]){ System.out.print(new A().j=23);}}
Consider the following code and choose the

Access correct option:


Specifiers class A{ int z; A(int x){z=x;} } Compiles but
Constructors class B extends A{ throws run Compiles and
Methods public static void main(String arg){ Compilation time displays None of the
NewQB new B();}} error exception nothing listed options 1 0 0 0
class Test{

static void method(){


this.display();
}
static display(){
System.out.println(("hello");
}
public static void main(String[] args){
Access new Test().method();
Specifiers }
Constructors }
Methods consider the code above & select the proper Runtime compiles but does not
NewQB output from the options. hello Error no output compile 0 0 0 1

What will be the result when you try to


compile and run the following code?
private class Base{ Base(){
int i = 100; System.out.println(i);
}

}
static int i = 200;
Access public static void main(String argv[]){
Specifiers Pri p = new Pri();
Constructors System.out.println(i);
Methods } 100 followed Compile time
NewQB } 200 by 200 error 100 0 0 1 0

public class MyClass {


static void print(String s, int i) { System.out.println("String: " + s + ", int: " +

i);
}
}

Access public static void main(String[] args) { String: String int: 27,

Specifiers print("String first", 11); first, int: 11 String: Int


Constructors print(99, "Int first"); int: 99, first String:
Methods } String: Int String first, Compilation Runtime
NewQB }What would be the output? first int: 27 Error Exception 1 0 0 0

A) No argument constructor is provided to all

Java classes by default


B) No argument constructor is provided to the
Access class only when no constructor is defined.
Specifiers C) Constructor can have another class object
Constructors as an argument
Methods D) Access specifiers are not applicable to Only A is B and C is All are
NewQB Constructor TRUE All are TRUE TRUE FALSE 0 0 1 0

Consider the following code and choose the

correct option:
class Test{ private static void display(){
Access System.out.println("Display()");}
Specifiers private static void show() { display(); Compiles and Compiles but
Constructors System.out.println("show()");} prints throws
Methods public static void main(String arg[]){ Compiles and Display() runtime Compilation
NewQB show();}} prints show() show() exception error 0 1 0 0
Which of the following sentences is true?

A) Access to data member depends on the


scope of the class and the scope of data
members
Access B) Access to data member depends only on
Specifiers the scope of the data members
Constructors C) Access to data member depends on the
Methods scope of the method from where it is Only A and C All are Only A is
NewQB accessed is TRUE All are TRUE FALSE TRUE 0 0 0 1
Given:
public class Yikes {

An exception
Compilation is thrown at
int Long Short Long fails. runtime. 1 0 0 0

System.out. System.out. System.out. System.out.


println(Math. println(Math. println(Math. println(Math.
Which of the following will print -4.0 ceil(-4.7)); floor(-4.7)); round(-4.7)); min(-4.7)); 1 0 0 0

Only B and C Only A is All are Only A and C


is TRUE TRUE FALSE is TRUE 1 0 0 0

Dog Man Cat


Dog Ant Ant Man Dog Ant Dog Man Ant 1 0 0 0

Compiles but Compiles and


doesn't throws run
display time Compilation Compiles and
anything exception fails displays Hi 0 0 1 0

prints Hi Compiler Runs but no Runtime


Hello Error output Error 0 1 0 0
Access Specifiers public static void go(Long n) {System.out.
Constructors Methods print("Long ");}
NewQB public static void go(Short n) {System.out. print("Short ");}
Access Specifiers public static void go(int n) {System.out.print
Constructors Methods ("int ");}
NewQB public static void main(String [] args) {
short y = 6; long z = 7; go(y);
go(z);
}
}
What is the result?

Access Specifiers Suppose class B is sub class of class A:


Constructors Methods A) If class A doesn't have any constructor, then class B also must not have any constructor
NewQB B) If class A has parameterized constructor, then class B can have default as well as parameterized constructor
C) If class A has parameterized constructor then call to class A constructor should be made explicitly by constructor of class B

Access Specifiers class Order{


Constructors Methods Order(){ System.out.println("Cat");
}
public static void main(String... Args){ System.out.println("Ant");
} static{ System.out.println("Dog");
}
{ System.out.println("Man");
}}
consider the code above & select the proper

NewQB output from the options.


Access Specifiers Consider the following code and choose the
Constructors Methods correct option:
class A{ private void display(){ System.out. print("Hi");}
public static void main(String ar[]){

NewQB display();}}
Access Specifiers Consider the following code and choose the
Constructors Methods correct option:
public class MyClass {
public static void main(String arguments[]) {
amethod(arguments);
}
public void amethod(String[] arguments) { System.out.println(arguments[0]); System.out.println(arguments[1]);
}
}

NewQB Command Line arguments - Hi, Hello


package QB;
class Sphere {
protected int methodRadius(int r) { System.out.println("Radious is: "+r);
return 0;
}
}

package QB;
public class MyClass {
public static void main(String[] args) {
double x = 0.89;
Access Sphere sp = new Sphere();
Specifiers // Some code missing
Constructors } sp. Sphere.
Methods } to get the radius value what is the code of methodRadiu methodRadiu Nothing to methodRadiu
NewQB line to be added ? s(x); s(x); add s(); 0 1 0 0
class One{

int var1;
One (int x){
var1 = x;
}}
class Derived extends One{
int var2;
void display(){
System.out.println("var 1="+var1+"var2="
+var2);
}}
class Main{
public static void main(String[] args){
Access Derived obj = new Derived();
Specifiers obj.display(); compiles
Constructors }} successfully
Methods consider the code above & select the proper but runtime
NewQB output from the options. 0,0 error compile error none of these 0 0 1
0 0

0 0

0 0

0 0

1 0

0 0
0 0
0
Methods public static void main(String args[]){ Compilation runs without Compiles and Compiles and

What will be printed out if you attempt to


compile and run the following code ?
public class AA {

i = this. this = new this.suns =


planets; i = this.suns; ThisUsage(); this.i = 4; planets; 0.33 0.33 0 0

Which modifier is used to control access to


critical code in multi-threaded programs? default public transient synchronized 0 0 0
Consider the following code and choose the

correct option:
class Test{ private void display(){
Access System.out.println("Display()");}
Specifiers private static void show() { display(); Compiles and Compiles but
Constructors System.out.println("show()");} prints throws
Methods public static void main(String arg[]){ Compiles and Display() runtime Compilation
NewQB show();}} prints show() show() exception error 0 0

Consider the following code and choose the

best option:
Access class Super{ int x; Super(){x=2;}}
Specifiers class Sub extends Super { void displayX(){
Constructors System.out.print(x);} Compiles and

NewQB new Sub().displayX();}} error any output display 2 display 0 0 0

class One{
int var1;
One (int x){
var1 = x;
}}
class Derived extends One{
int var2;
Derived(){
super(10);
var2=10;
}
void display(){
System.out.println("var1="+var1+" , var2="
+var2);
}}
class Main{
public static void main(String[] args){
Access Derived obj = new Derived();
Specifiers obj.display();
Constructors }}
Methods consider the code above & select the proper var1=10 ,
NewQB output from the options. var2=10 0,0 compile error runtime error 1 0

public class MyAr {

static int i1;


public static void main(String argv[]) {
MyAr m = new MyAr();
m.amethod();
} It is not
Access public void amethod() { possible to
Specifiers System.out.println(i1); access a
Constructors } static variable
Methods } Compilation Garbage in side of non
NewQB What is the output of the program? Error Value static method 1 0

public static void main(String[] args) {


int i = 9;
switch (i) {
default:
System.out.println("default");
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
Access case 2:
Specifiers System.out.println("two");
Constructors }
Methods } Compilation default zero
NewQB } Error default default zero one two 0 0

Access Specifiers Constructors Which statements, when inserted at (1), will


Methods NewQB not result in compile-time errors?
Access Specifiers Constructors public class ThisUsage {
Methods NewQB int planets; static int suns; public void gaze() { int i;
// (1) INSERT STATEMENT HERE
}
}
0 0 0.33

0 1

1 0
0 0

0 0

1 0
Given:
package QB;

public Sandwich() {
System.out.println("Sandwich()");
}
Meal() Meal() Cheese()
Meal() Cheese() Lunch() Sandwich()
Lunch() Lunch() PortableLunc Meal()
PortableLunc PortableLunc h() Lunch()
h() Cheese() h() Sandwich() PortableLunc
Sandwich() Sandwich() Cheese() h() 1 0 0 0

compiles and compilation Compiles and Compiles and


display 0 error display 4 display 3 1 0 0 0

20 and 40 10 and 40 10, and 20 0 0 1 0

class Meal {
Meal() { System.out.println("Meal()");

}
}
class Cheese {
Cheese() { System.out.println("Cheese()");
}
}
class Lunch extends Meal {
Lunch() { System.out.println("Lunch()");

}
}
class PortableLunch extends Lunch {
PortableLunch() { System.out.println("PortableLunch()");

}
}
class Sandwich extends PortableLunch {
private Cheese c = new Cheese();
Access Specifiers }
Constructors Methods public class MyClass7 {
NewQB public static void main(String[] args) {
new Sandwich();
}
} What would be the output?

Access Specifiers Consider the following code and choose the


Constructors Methods correct option:
NewQB class A{ int a; A(int a){a=4;}}
class B extends A{ B(){super(3);} void displayA(){
System.out.print(a);}
public static void main(String args[]){
new B().displayA();}}

Access Specifiers Given the following code what will be output? Error: amethod parameter does not match variable
Constructors Methods public class Pass{
NewQB static int j=20;
public static void main(String argv[]){
int i=10;
Pass p = new Pass(); p.amethod(i); System.out.println(i);
System.out.println(j);
}

public void amethod(int x){


x=x*2;
j=j*2;
}
}

The compiler

will
automatically The program
Access change the The compiler will compile
Specifiers What will happen if a main() method of a private will find the The program successfully,
Constructors "testing" class tries to access a private variable to a error and will will compile but the .class
Methods instance variable of an object using dot public not make a . and run file will not
NewQB notation? variable class file successfully run correctly 0 1 0
11. class Mud {

12. // insert code here


13. System.out.println("hi");
14. }
15. }
And the following five fragments:
public static void main(String...a) {
public static void main(String.* a) {
Access public static void main(String... a) {
Specifiers public static void main(String[]... a) {
Constructors public static void main(String...[] a) {
Methods How many of the code fragments, inserted
NewQB independently at line 12, compile? 1 2 3 0 0 0

class Order{

Order(){
System.out.println("Cat");
}
public static void main(String... Args){
Order obj = new Order();
System.out.println("Ant");
}
static{
System.out.println("Dog");
}
Access {
Specifiers System.out.println("Man");
Constructors }}
Methods consider the code above & select the proper Man Dog Cat Cat Ant Dog Dog Man Cat
NewQB output from the options. Ant Man Ant compile error 0 0 1
0 0

0 0

1 0
0

0
A Sequence A Sequence
of 5 zero's of 5 one's will will
be printed be printed IndexOutOfB
NewQB } like 0 0 0 0 0 like 1 1 1 1 1 oundes Error

2 1

Methods A constructor may return value including class


NewQB type true false

Compilation Compiles and Compiles and Compiles but


NewQB System.out.print(new S().roll);}} error display 0 display 23

Compilation
NewQB What is the output? Hellow Error

class MyClass1

NewQB What would be the output? error Exception 2500

Compilation
and output of
NewQB What is the Output of the Program? null

Compilation
and output of
null

Compilation
What is the output? Hello Error

synchronized volatile transient


synchronized volatile transient
Access Specifiers abstract class MineBase { Compilation Error occurs and to avoid them we need to declare Mine class as abstract
Constructors Methods abstract void amethod();
static int i;
}
public class Mine extends MineBase { public static void main(String argv[])
{ int[] ar=new int[5];
for(i=0;i < ar.length;i++) System.out.println(ar[i]);
}

Access Specifiers public class Q { Compiler Error: anar is referenced Compiler Error: size of array must be
Constructors Methods public static void main(String argv[]) { int anar[] = new before it is
int[] { 1, 2, 3 }; System.out.println(anar[1]);
}

NewQB } initialized defined


Access Specifiers Constructors

Access Specifiers Consider the following code and choose the


Constructors Methods correct option:
package aj; class S{ int roll =23;
private S(){} }
package aj; class T
{ public static void main(String ar[]){

Access Specifiers public class c123 { It is not possible to declare a constructor as private
Constructors Methods private c123() { System.out.println("Hellow");
}
public static void main(String args[]) {
c123 o1 = new c123();
c213 o2 = new c213();
}
}
class c213 { private c213() { System.out.println("Hello123");
}
}

{
private int area(int side)
{
return(side * side);
}
public static void main(String args[ ])
{
MyClass1 MC = new MyClass1( );
Access int area = MC.area(50);
Specifiers System.out.println(area);
Constructors }
Methods } Compilation Runtime
Access Specifiers public class MyAr { Compile time error
Constructors Methods public static void main(String argv[]) { MyAr m = new MyAr(); because i
m.amethod(); has not been initialized
}
public void amethod() { static int i1; System.out.println(i1);
}
}
Access Specifiers public class MyAr { Unresolved compilation problem: The local variable i1 may not have been initialized
Constructors Methods public static void main(String argv[]) { MyAr m = new MyAr();
NewQB m.amethod();
}
public void amethod() { final int i1; System.out.println(i1);
}
}
What is the Output of the Program?

Access Specifiers public class c1 { It is not possible to declare a


Constructors Methods private c1() constructor private
NewQB {
Access Specifiers System.out.println("Hello");
Constructors Methods }
NewQB public static void main(String args[])
{
c1 o1=new c1();
}
}

Which modifier indicates that the variable might be modified


asynchronously, so that all threads will get the correct value of the
variable.
IndexOutOfB
oundes Error 0 0 0 1

0 1 0 0

0 1

es and Compiles and Compiles but


no output 1 0 0 0

Runs without
any output 0 0 1 0

50 0 0 1 0

Compilation
and output of
null 0 0 0 1

Compilation
and output of None of the
null given options 0 1 0 0

1 0 0 0

default 0 1 0 0
default 0 1 0 0
Compilation Error occurs and to avoid them we need to declare Mine class as abstract

Compiler Error: size of array must be

defined

ssible to declare a constructor as private

It is not
possible to declare a static variable in side of non static method or instance method. Because Static
variables are class level dependencie s.
d compilation problem: The local variable i1 may not have been initialized

Can't create object because constructor is private


class A {
int i, j;

}
class B extends A {
int k;

This is j: 5 i This is i: 3 j This is i: 7 j This is k: 7 i


} What would be the ouput? and k: 3 7 and k: 5 7 and k: 3 5 and j: 3 7 0 0 0 1

Compiles and
Compiles and runs without Compiles and Compilation
new Y().displayX();}} display 2 any output display 0 error 0 0 0 1

Dog Cat Ant Ant Cat Dog none 0 1 0 0

Compile time A random


error referring number
to a cast between 1
problem and 10 1 0 0 0

Override Retention Depricated Documented Target 0 0.333333 0 0.333333

Annotations_
NewQB method class source runtime 0 1 0 0

Annotations_ CONSTRUC
NewQB SOURCE METHOD TOR CLASS 0.333333 0 0.333333 0

Information
Annotations_ Select the Uses of annotations. (Choose For the Information Runtime Information
NewQB THREE) Compiler for the JVM processing for the OS 0.333333 0 0.333333 0.333333

All annotation types should maually extend


the Annotation interface. State TRUE/FALSE true false 0 1
all the listed
Custom annotations can be created using @interface @inherit @include options 1 0 0 0

public void x() {} }


And:

A(int a, int b) {
i = a;
j = b;

}
void show() {
System.out.println("i and j: " + i + " " + j);

}
B(int a, int b, int c) {
super(a, b);
k = c;

}
void show(String msg) { System.out.println(msg + k);

}
}
Access Specifiers class Override {
Constructors Methods public static void main(String args[]) { B subOb = new B(3, 5, 7); subOb.show("This is k: "); // this calls
NewQB show() in B
subOb.show(); // this calls show() in A
}

Access Specifiers Consider the following code and choose the


Constructors Methods correct option:
NewQB class X { int x; X(int x){x=2;}}
class Y extends X{ Y(){} void displayX(){ System.out.print(x);}
public static void main(String args[]){

Access Specifiers class Order{


Constructors Methods Order(){ System.out.println("Cat");
NewQB }
public static void main(String... Args){ Order obj = new Order(); System.out.println("Ant");
} static{ System.out.println("Dog");
}}
consider the code above & select the proper
output from the options. Cat Ant Dog

Access Specifiers What will be the result when you attempt to A random number between 0 A compile time error as random being an undefined method
Constructors Methods compile this program? and 1
NewQB public class Rand{
Annotations_ NewQB public static void main(String argv[]){
int iRand;
iRand = Math.random(); System.out.println(iRand);
} RUNTIME Compile time
} and deploytime processing
Choose the meta annotations. (Choose
THREE)
If no retention policy is specified for an annotation, then the default policy
of
is used.
Select the variable which are in java.lang. annotation.RetentionPolicy
class. (Choose THREE)

Annotations_
NewQB Annotations_
NewQB

Given:
10. interface A { void x(); }
11. class B implements A {
public void x() { }
public void y() { } }
12. class C extends B {

20. java.util.List<a> list = new java.util.


ArrayList</a>();
21. list.add(new B());
22. list.add(new C());
23. for (A a:list) {
24. a.x(); Compilation Compilation Compilation
25. a.y();; fails because The code An exception fails because fails because
Collections_u 26. } of an error in runs with no is thrown at of an error in of an error in
til_NewQB What is the result? line 25 output. runtime line 21 line 23. 1 0 0
0 1

0 0

0.333333 0.333333

0 0

33333 0 0.333333

33333 0.333333 0

0 0
0 0
The program
Collections_u will not compile
til_NewQB } output: [B] 0 0 1 0

The before() The before() The before()


Collections_u method will method will method will not
til_NewQB } print 1 2 print 1 2 3 compile 0 0 1 0

Collections_u Today is Today is none of the


til_NewQB }} Holiday Holiday Both listed options 0 1 0 0

The code
Collections_u Compilation runs with no
til_NewQB 1, 2, 3, fails. output. 0 0 1 0

Which collection class allows you to grow or


shrink its size and provides indexed access to its java.util.
Collections_u elements, but its methods are not java.util. LinkedHashS java.util. java.util.
til_NewQB synchronized? HashSet et java.util.List ArrayList Vector 0 0 0 1

Collections_u int indexOf(Object o) - What does this method none of the


til_NewQB return if the element is not found in the List? null -1 listed options 0 1 0 0

Compiles but
Collections_u Compilation exception at
til_NewQB error prints 3,4,2,1, prints 1,2,3,4 runtime 0 0 1
Given:

public static Collection get() {


Collection sorted = new LinkedList();
sorted.add("B"); sorted.add("C"); sorted.add
("A");
return sorted;
}
public static void main(String[] args) {
for (Object obj: get()) {
System.out.print(obj + ", ");
} An exception
Collections_u } Compilation is thrown at
til_NewQB What is the result? A, B, C, B, C, A, fails. runtime. 0 1

Which statement is true about the following The program The program The program
program?
import java.util.ArrayList; import java.util.Collections; import java.util.List;
public class WhatISThis {
public static void main(String[] na){ List<StringBuilder> list=new
ArrayList<StringBuilder>(); list.add(new StringBuilder("B")); list.add(new
StringBuilder("A")); list.add(new StringBuilder("C")); Collections.sort(list,Collections.

reverseOrder()); will compile will compile will compile


System.out.println(list.subList(1,2)); and print the and print and throw a runtime exception
} following the following
output: [B,A]

Consider the following code and choose the The before() method will throw an exception at runtime
correct option:
public static void before() { Set set = new TreeSet(); set.add("2");
set.add(3);
set.add("1");
Iterator it = set.iterator(); while (it.hasNext()) System.out.print(it.next() + " ");

import java.util.StringTokenizer;
class ST{
public static void main(String[] args){ String input = "Today is$Holiday"; StringTokenizer st = new StringTokenizer (input,"$");
while(st.hasMoreTokens()){ System.out.println(st.nextElement());

Given:
public static Iterator reverse(List list) { Collections.reverse(list);
return list.iterator();
}
public static void main(String[] args) { List list = new ArrayList();
list.add("1"); list.add("2"); list.add("3"); for (Object obj: reverse(list)) System.out.print(obj + ", ");
}
What is the result? 3, 2, 1,

What is the result of attempting to compile

and run the following code?


import java.util.Vector; import java.util.
LinkedList; public class Test1{ public static
void main(String[] args) { Integer int1 = new
Integer(10); Vector vec1 = new Vector();
LinkedList list = new LinkedList(); vec1.add
(int1); list.add(int1); if(vec1.equals(list))
System.out.println("equal"); else System.out.
println("not equal"); } } 1. The code will fail to
compile. 2. Runtime error due to incompatible
Collections_u object comparison 3. Will run and print
til_NewQB "equal". 4. Will run and print "not equal". 1 2 3 4 0 0

Consider the following code and choose the


correct option:
class Test{
public static void main(String args[]){ Integer arr[]={3,4,3,2};
Set<Integer> s=new TreeSet<Integer> (Arrays.asList(arr));
s.add(1); for(Integer ele :s){ System.out.println(ele); } }}
1 0

1 0

0 0

1 0

0 1 0

0 0

0
0 0

1 0
Consider the following code and choose the
correct output:
class Test{

public class MainClass {

elements = new String[] { "A", "B", "C", "D"


};
Set set2 = new HashSet(Arrays.asList
(elements));

System.out.println(set.equals(set2));
Collections_u } Compile time Runtime
til_NewQB } What is the result of given code? true false error Exception 0 1 0 0

Collections_u A and B is A and D is


til_NewQB D) Vector class is not synchronized TRUE TRUE 0 0 1 0
Collections_u
til_NewQB Java.util.Map Java.util.List 1 0 0 0

Collections_u none of the


til_NewQB -1 null listed options 0 0 1 0
Inorder to remove one element from the given
Treeset, place the appropriate line of code public class Main {
public static void main(String[] args) { TreeSet<Integer> tSet = new
TreeSet<Integer>(); System.out.println("Size of TreeSet : " +
tSet.size());
tSet.add(new Integer("1")); tSet.add(new Integer("2")); tSet.add(new Integer("3")); System.out.println(tSet.size());
// remove the one element from the Treeset
System.out.println("Size of TreeSet after

removal : " + tSet.size()); tSet.clear tSetdelete tSet.remove tSet.drop


Collections_u } (new Integer (new Integer (new Integer (new Integer
til_NewQB } ("1")); ("1")); ("1")); ("1")); 0 0 1 0

Consider the code below & select the correct

ouput from the options:


public class Test{
public static void main(String[] args) {
String []colors={"orange","blue","red","
green","ivory"};
Arrays.sort(colors);
int s1=Arrays.binarySearch(colors, "ivory");
Collections_u int s2=Arrays.binarySearch(colors, "silver");
til_NewQB System.out.println(s1+" "+s2); }} 2 -4 3 -5 2 -6 3 -4 0 0 1 0
public static void main(String args[]){
TreeMap<Integer, String> hm=new
TreeMap<Integer, String>();
hm.put(2,"Two");
hm.put(4,"Four");
hm.put(1,"One");
hm.put(6,"Six");
hm.put(7,"Seven");
SortedMap<Integer, String> sm=hm.subMap
(2,7);
SortedMap<Integer,String> sm2=sm.tailMap {2=Two,
(4); 4=Four, {4=Four, {2=Two,
Collections_u System.out.print(sm2); 6=Six, 6=Six, {4=Four, 4=Four,
til_NewQB }} 7=Seven} 7=Seven} 6=Six} 6=Six} 0 0 1 0
Collections_u next() method of Scanner class will return
til_NewQB Integer Long int String 0 0 0 1
Given:
import java.util.Arrays; import java.util.HashSet; import java.util.Set;

public static void main(String[] a) {


String elements[] = { "A", "B", "C", "D", "E"
};
Set set = new HashSet(Arrays.asList
(elements));
A)Property files help to decrease coupling A and C is B and D is
B) DateFormat class allows you to format dates and times with customized styles. C) Calendar class TRUE Java.util. TRUE Java.util.
allows to perform date Table Collection
calculation and conversion of dates and times between timezones.

Which interface does java.util.Hashtable implement?


Object get(Object key) - What does this method return if the key is not found in the Map?

Consider the following code and choose the


correct option:
class Test{
public static void main(String args[]){ TreeSet<Integer> ts=new
TreeSet<Integer>();

ts.add(1);
ts.add(8);
ts.add(6);
ts.add(4);
SortedSet<Integer> ss=ts.subSet(2, 10);
ss.add(9);
System.out.println(ts);
Collections_u System.out.println(ss); [1,4,6,8] [1,8,6,4] [1,4,6,8,9] [1,4,6,8,9]
til_NewQB }} [4,6,8,9] [8,6,4,9] [4,6,8,9] [4,6,8] 0 0 1 0
0

0
0

1
Collections_u
til_NewQB }

Collections_u
til_NewQB System.out.print(sd.format(date));}}

A) Iterator does not allow to insert elements

during traversal
B) Iterator allows bidirectional navigation.
C) ListIterator allows insertion of elements
during traversal
Collections_u D) ListIterator does not support bidirectional A and B is A and D is A and C is B and D is
til_NewQB navigation TRUE TRUE TRUE TRUE 0 0 1 0
Collections_u static void sort(List list) method is part of Collection Collections ArrayList
til_NewQB interface class Vector class class 0 1 0 0
Collections_u static int binarySearch(List list, Object key) is ArrayList Collection Collections
til_NewQB a method of Vector class class interface class 0 0 0 1
Which collection class allows you to access

its elements by associating a key with an


Collections_u element's value, and provides java.util. java.util. java.util. java.util.
til_NewQB synchronization? SortedMap TreeMap TreeSet Hashtable 0 0 0 1
Consider the following code and select the
correct output:
import java.util.ArrayList; import java.util.LinkedList; import java.util.List;
public class Lists {
public static void main(String[] args) { List<String> list=new ArrayList<String>(); list.add("1");
list.add("2");
list.add(1, "3");
List<String> list2=new LinkedList<String> (list);
list.addAll(list2);
list2 =list.subList(2,5); list2.clear(); System.out.println(list);
}

[1,3,2] [1,3,3,2] [1,3,2,1,3,2] [3,1,2] [3,1,1,2] 1 0 0 0 0

Given:

import java.util.*;

public class LetterASort{

public static void main(String[] args) {


ArrayList<String> strings = new
ArrayList<String>();
strings.add("aAaA");
strings.add("AaA");
strings.add("aAa");
strings.add("AAaa");
Collections.sort(strings);
for (String s : strings) { System.out.print(s + "
"); }
}
Collections_u } Compilation aAaA aAa AAaa AaA AaA AAaa
til_NewQB What is the result? fails. AAaa AaA aAa aAaA aAaA aAa 0 0 1 0

A) It is a good practice to store heterogenous

data in a TreeSet.
B) HashSet has default initial capacity (16)
and loadfactor(0.75)
C)HashSet does not maintain order of
Collections_u Insertion A and B is A and D is A and C is B and C is
til_NewQB D)TreeSet maintains order of Inserstion TRUE TRUE TRUE TRUE 0 0 0 1
TreeSet<String> s = new TreeSet<String>();

TreeSet<String> subs = new


TreeSet<String>();
s.add("a"); s.add("b"); s.add("c"); s.add("d");
s.add("e");

subs = (TreeSet)s.subSet("b", true, "d", true);

s.add("g");
s.pollFirst();
s.pollFirst();
Collections_u s.add("c2"); The size of s The size of s The size of The size of s The size of
til_NewQB System.out.println(s.size() +" "+ subs.size()); is 4 is 5 subs is 3 is 7 subs is 1 0 0.5 0.5 0
Consider the following code was executed on

June 01, 1983. What will be the output?


class Test{
public static void main(String args[]){ Date date=new Date(); SimpleDateFormat sd;
sd=new SimplpeDateFormat("E MMM dd yyyy");

Wed Jun 01 244 JUN 01 PST JUN 01 GMT JUN 01


1983 1983 1983 1983 1 0 0 0

Given:

public class Venus {


public static void main(String[] args) {
int [] x = {1,2,3};
int y[] = {4,5,6};
new Venus().go(x,y);
}
void go(int[]... z) {
for(int[] a : z)
System.out.print(a[0]);
Collections_u }
til_NewQB } What is the result? 123 12 14 1 0 0 1 0
0
0

0 0
You wish to store a small amount of data and

make it available for rapid access. You do not


have a need for the data to be sorted,
uniqueness is not an issue and the data will
remain fairly static Which data structure might
be most suitable for this requirement?

1) TreeSet

2) HashMap
Collections_u 3) LinkedList
til_NewQB 4) an array 1 2 3 4 0 0 0

What will be the output of following code?

class Test{
public static void main(String args[]){
TreeSet<Integer> ts=new
TreeSet<Integer>();
ts.add(2);
ts.add(3);
ts.add(7);
ts.add(5);
SortedSet<Integer> ss=ts.subSet(1,7);
ss.add(4);
Collections_u ss.add(6);
til_NewQB System.out.print(ss);}} [2,3,7,5] [2,3,7,5,4,6] [2,3,4,5,6,7] [2,3,4,5,6] 0 0 0
Consider the following code and choose the
correct option:
class Data{ Integer data; Data(Integer d)
{data=d;}
public boolean equals(Object o){return true;}
public int hasCode(){return 1;}}
class Test{
public static void main(String ar[]){ Set<Data> s=new HashSet<Data>(); s.add(new Data(4));
s.add(new Data(2));
s.add(new Data(4));

s.add(new Data(1)); Collections_u s.add(new Data(2)); Compiles but


til_NewQB System.out.print(s.size());}} 3 compilation error at run
5 error time 0 1 0

Consider the code below & select the correct

ouput from the options:


public class Test{
public static void main(String[] args) {
String num="";
Control z: for(int x=0;x<3;x++)
structures for(int y=0;y<2;y++){
wrapper if(x==1) break;
classes auto if(x==2 && y==1) break z;
boxing num=num+x+y; Compilation
NewQB }System.out.println(num);}} 0001 120 12021 error 0 1 0

Given:

public class Test {


public enum Dogs {collie, harrier};
public static void main(String [] args) {
Dogs myDog = Dogs.collie;
switch (myDog) {
case collie:
System.out.print("collie ");
Control case harrier:
structures System.out.print("harrier ");
wrapper }
classes auto }
boxing } Compilation
NewQB What is the result? collie harrier fails. collie harrier 0 0 0

Consider the following code and choose the

correct output:
Control class Test{
structures public static void main(String args[]){
wrapper boolean flag=true;
classes auto if(flag=false){
boxing System.out.print("TRUE");}else{ compilation
NewQB System.out.print("FALSE");}}} true false error Compiles 0 1 0

Cosider the following code and choose the

Control correct option:


structures class Test{
wrapper public static void main(String args[]){
classes auto System.out.println(Integer.parseInt NumberForm
boxing ("2147483648", 10)); Compilation 2.147483648 atException Compiles but
NewQB }} error E9 at run time no output 0 0 1

Given:

public class Test {


public enum Dogs {collie, harrier, shepherd};
public static void main(String [] args) {
Dogs myDog = Dogs.shepherd;
switch (myDog) {
case collie:
System.out.print("collie ");
case default:
System.out.print("retriever ");
Control case harrier:
structures System.out.print("harrier ");
wrapper }
classes auto }
boxing } Compilation
NewQB What is the result? harrier shepherd retriever fails. 0 0 0
1

0
1
Given:
static void myFunc()
{
int i, s = 0;
for (int j = 0; j < 7; j++) {
i = 0;
do {
i++;
Control s++;
structures } while (i < j);
wrapper }
classes auto System.out.println(s);
boxing }
NewQB } What would be the result 20 21 22 23 24 0 0 1 0 0
Control

structures
wrapper
classes auto What is the range of the random number r
boxing generated by the code below?
NewQB int r = (int)(Math.floor(Math.random() * 8)) + 2; 2 <= r <= 9 3 <= r <= 10 2<= r <= 10 3 <= r <= 9 1 0 0 0

class Test{

public static void main(String[] args) {


int x=-1,y=-1;
if(++x=++y)
System.out.println("R.T. Ponting");
Control else
structures System.out.println("C.H. Gayle");
wrapper }
classes auto }
boxing consider the code above & select the proper none of the
NewQB output from the options. R.T.Ponting C.H.Gayle Compile error listed options 0 0 1 0

Given:

public class Breaker2 {


static String o = "";
public static void main(String[] args) {
z:
for(int x = 2; x < 7; x++) {
if(x==3) continue;
if(x==5) break z;
Control o = o + x;
structures }
wrapper System.out.println(o);
classes auto }
boxing }
NewQB What is the result? 2 24 234 246 0 1 0 0

Consider the following code and choose the

correct output:
Control class Test{
structures public static void main(String args[]){
wrapper int a=5;
classes auto if(a=3){
boxing System.out.print("Three");}else{ Compilation Compiles but
NewQB System.out.print("Five");}}} error Three Five no output 1 0 0 0

Given:

public class Batman {


int squares = 81;
public static void main(String[] args) {
new Batman().go();
}
void go() {
Control incr(++squares);
structures System.out.println(squares);
wrapper }
classes auto void incr(int squares) { squares += 10; }
boxing }
NewQB What is the result? 81 82 91 92 0 1 0 0
public void foo( boolean a, boolean b)
{
if( a )
{
System.out.println("A"); /* Line 5 */
}
else if(a && b) /* Line 7 */
{
System.out.println( "A && B");
}
else /* Line 11 */
{
if ( !b )
{
System.out.println( "notB") ;
}
else
{
Control System.out.println( "ELSE" ) ;
structures } If a is true If a is true If a is false If a is false
wrapper } and b is false and b is true and b is false and b is true
classes auto } then the then the then the then the
boxing output is output is "A output is output is
NewQB What would be the result? "notB" && B" "ELSE" "ELSE" 0 0 0

What is the value of ’n’ after executing the

following code?
int n = 10;
int p = n + 5;
int q = p - 10;
int r = 2 * (p - q);
switch(n)
Control {
structures case p: n = n + 1;
wrapper case q: n = n + 2;
classes auto case r: n = n + 3;
boxing default: n = n + 4; Compilation Runtime
NewQB } 14 28 Error 10 Error 0 0 1
1 0 0

0 0

1 0

0 0
0 0

0 0
iOb =
Integer(100);
public class While
{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{

System.out.print("x plus one is " + (x +


Control 1)); /* Line 8 */
structures }
wrapper } There are There are
classes auto } There is a syntax errors syntax errors There is a
boxing syntax error on lines 1 on lines 1, 6, syntax error
NewQB Which statement is true? on line 1 and 6 and 8 on line 6 0 0 0 1

Which of the following loop bodies DOES

compute the product from 1 to 10 like (1 * 2 *


3*4*5*
Control 6 * 7 * 8 * 9 * 10)?
structures int s = 1;
wrapper for (int i = 1; i <= 10; i++)
classes auto {
boxing <What to put here?> Compilation
NewQB } s += i * i; s++; s = s + s * i; s *= i; error 0 0 0 1

Control

structures
wrapper Character
classes auto String is a Double has a has a String is the
boxing Which of the following statements are true wrapper compareTo() intValue() Byte extends wrapper
NewQB regarding wrapper classes? (Choose TWO) class method method Number class of char 0 0.5 0 0.5

Given:

class Atom {
Atom() { System.out.print("atom "); }
}
class Rock extends Atom {
Rock(String type) { System.out.print(type); }
}
public class Mountain extends Rock {
Mountain() {
super("granite ");
Control new Rock("granite ");
structures }
wrapper public static void main(String[] a) { new
classes auto Mountain(); }
boxing } Compilation granite atom granite atom granite
NewQB What is the result? fails. granite granite atom granite 0 0 0 1

What are the thing to be placed to complete


the code?
class Wrap {
public static void main(String args[]) {

Control int i = iOb.intValue();

structures
wrapper System.out.println(i + " " + iOb); // displays
classes auto 100 100
boxing }
NewQB } int, int Integer, new Integer, int int, Integer 0 1 0 0
public class SwitchTest
{
public static void main(String[] args)
{
(4)); System.out.println("value =" + switchIt
}

public static int switchIt(int x)


{
int j = 1;
switch (x)
{

Control structures wrapper case 1: j++;


classes auto case 2: j++; case 3: j++; case 4: j++; case 5: j++; default: j++;
}
return j + x;
}

boxing }
NewQB What will be the output of the program? value = 8 value = 2 value = 4 value = 6 1 0 0 0
Given:

public class Barn {


public static void main(String[] args) {
new Barn().go("hi", 1);
new Barn().go("hi", "world", 2);
Control }
structures public void go(String... y, int x) {
wrapper System.out.print(y[y.length - 1] + " ");
classes auto }
boxing } Compilation
NewQB What is the result? hi hi hi world world world fails. 0 0 0 1

Consider the following code and choose the

correct option:
class Test{
Control public static void main(String args[]){ int
structures x=034;
wrapper int y=12;
classes auto int ans=x+y; Compiles but
boxing System.out.println(ans); compilation error at run
NewQB }} 40 46 error time 1 0 0 0
1

1 0

0.5 0

1
What will be thr result? 3 2 4 1 0 0 0 1

fail to compile determine compile compile compile


because the which if correctly and correctly and correctly,but
syntax of the if statement the display the display the will not
statement else clause letter a,when letter b,when display any
}} is incorrect belongs to run run output 0 0 0 1 0

good morning compiler


morning …. error runtime error 0 0 1 0

Compilation bat man


bat man error spider man spider man 0 0 1 0
11. double input = 314159.26;

12. NumberFormat nf = NumberFormat.


Control getInstance(Locale.ITALIAN);
structures 13. String b;
wrapper 14. //insert code here
classes auto b = nf.
boxing Which code, inserted at line 14, sets the value b = nf.parse( b = nf.format( b = nf.equals( parseObject(
NewQB of b to 314.159,26? input ); input ); input ); input ); 0 1 0

Consider the following code and choose the

correct option:
class Test{
public static void main(String ar[]){
TreeMap<Integer,String> tree = new
TreeMap<Integer,String>();
tree.put(1, "one");
tree.put(2, "two");
tree.put(3, "three");
Control tree.put(4,"Four");
structures System.out.println(tree.higherKey(2));
wrapper System.out.println(tree.ceilingKey(2));
classes auto System.out.println(tree.floorKey(1));
boxing System.out.println(tree.lowerKey(1));
NewQB }} 3 2 1 null 3211 2211 4211 1 0 0

Control Consider the following code and choose the

structures correct option:


wrapper class Test{
classes auto public static void main(String args[]){ Compiles but
boxing Long data=23; Compilation error at run None of the
NewQB System.out.println(data); }} 23 error time listed options 0 1 0

class AutoBox {

public static void main(String args[]) {

int i = 10;

Control Integer iOb = 100;


structures i = iOb;
wrapper System.out.println(i + " " + iOb);
classes auto } No,
boxing } whether this code work properly, if so what Compilation No, Runtime Yes, 100,
NewQB would be the result? error error Yes, 10, 100 100 0 0 0

Control Consider the following code and choose the

structures correct option:


wrapper class Test{
classes auto public static void main(String args[]){
boxing Long l=0l; Compilation
NewQB System.out.println(l.equals(0));}} error true false 1 0 0 1
int I = 0;
outer:
while (true)
{

I++;
inner:
for (int j = 0; j < 10; j++)
{

Control structures I += j;
wrapper classes auto if (j == 3)
boxing NewQB continue inner;
break outer;
}
continue outer;
} System.out.println(I);

Control structures what will be the result of attempting to compile The code will fail to compile because the compiler will
wrapper classes auto and run the following class? Public class IFTest{ The code will not be able to The code will The code will The code will
boxing NewQB public static void main(String[] args){
int i=10; if(i==10) if(i<10)
System.out.println("a"); else System.out.println("b");

Control structures What is the output of the following code :


wrapper classes auto class try1{
boxing NewQB public static void main(String[] args) { System.out.println("good"); while(false){ System.out.println("morning");
}
}
} good
Control structures Consider the following code and choose the
wrapper classes auto correct output:
boxing NewQB class Test{
public static void main(String args[]){
int num=3; switch(num){ case 1: case 3: case 4: { System.out.println("bat man"); } case 2: case 5: {
System.out.println("spider man"); }break; }
}}
1

1 0

0
0

0
What will be the output of following code?

one two three four three two four one one two three
} four one three two four one 0 0 1 0

3 23 123 0 0 1 0

HashTable is ArrayList is a LinkedList is Stack is a


a sub class of sub class of a subclass of subclass of
Which of these statements are true? Dictionary Vector ArrayList Vector 0.5 0 0 0.5

Given:

int n = 10;
switch(n)
{
case 10: n = n + 1;
case 15: n = n + 2;
case 20: n = n + 3;
Control case 25: n = n + 4;
structures case 30: n = n + 5;
wrapper }
classes auto System.out.println(n);
boxing What is the value of ’n’ after executing the Compilation
NewQB following code? 23 32 25 Error Runtine Error 0 0 1 0

Control structures TreeSet map = new TreeSet();


wrapper classes auto map.add("one"); map.add("two"); map.add("three"); map.add("four"); map.add("one");
boxing NewQB Iterator it = map.iterator();
while (it.hasNext() )
{
System.out.print( it.next() + " " );

public class Test {


public static void main(String [] args) {
int x = 5;
boolean b1 = true;
boolean b2 = false;

Control structures if ((x == 4) && !b2 )


wrapper classes auto System.out.print("1 "); System.out.print("2 "); if ((b2 = true) && b1 ) System.out.print("3 ");
boxing NewQB }
}
What is the result? 2

Control
structures wrapper classes auto boxing NewQB

Given:

import java.util.*;
public class Explorer3 {
public static void main(String[] args) {
TreeSet<Integer> s = new
TreeSet<Integer>();
TreeSet<Integer> subs = new
TreeSet<Integer>();
for(int i = 606; i < 613; i++)
if(i%2 == 0) s.add(i);
subs = (TreeSet)s.subSet(608, true, 611,
Control true);
structures subs.add(629);
wrapper System.out.println(s + " " + subs); [608, 610,
classes auto } [608, 610, An exception 612, 629]
boxing } Compilation 612, 629] is thrown at [608, 610,
NewQB What is the result? fails. [608, 610] runtime. 629] 0 0 1 0

What is the output :

class try1{
public static void main(String[] args) {
int x=1;
Control if(x--)
structures System.out.println("good");
wrapper else
classes auto System.out.println("bad");
boxing }
NewQB } good bad compile error run time error 0 0 1 0

Consider the following code and choose the

correct output:
class Test{
public static void main(String args[]){
int num='b'; switch(num){
Control default :{
structures System.out.print("default");}
wrapper case 100 : case 'b' : case 'c' : {
classes auto System.out.println("brownie"); break;}
boxing case 200: case 'e': { default compilation
NewQB System.out.println("pastry"); }break; } }} brownie brownie error default 1 0 0 0

Given:

int a = 5;
int b = 5;
int c = 5;
if (a > 3)
if (b > 4)
if (c > 5)
c += 1;
else
Control c += 2;
structures else
wrapper c += 3;
classes auto c += 4;
boxing What is the value of variable c after executing
NewQB the following code? 3 5 7 9 11 0 0 0 0
0 0
0 1
Examine the following code:

What condition should be used so that the


code prints:

12345678 count < 9 count+1 <= 8 count < 8 count != 8 1 0 0 0

What will be the output of the program?

Compilation

Given:

Float pi = new Float(3.14f);


if (pi > 3) {
System.out.print("pi is bigger than 3. ");
}
else {
Control System.out.print("pi is not bigger than 3. ");
structures }
wrapper finally {
classes auto System.out.println("Have a nice day."); An exception pi is bigger
boxing } Compilation pi is bigger occurs at than 3. Have
NewQB What is the result? fails. than 3. runtime. a nice day. 1 0 0

Given:

public void go() {


String o = "";
z:
for(int x = 0; x < 3; x++) {
for(int y = 0; y < 2; y++) {
if(x==1) break;
if(x==2 && y==1) break z;
o = o + x + y;
Control }
structures }
wrapper System.out.println(o);
classes auto }
boxing What is the result when the go() method is
NewQB invoked? 0 1 120 12021 0 0 1

int count = 1;
while ( )
{

System.out.print( count + " " );


count = count + 1;
}

Control System.out.println( );
structures wrapper classes
auto boxing NewQB

public class Switch2


{
final static short x = 2;
public static int y = 0;
public static void main(String [] args)
{

for (int z=0; z < 3; z++)


{
switch (z)
{
Control structures Line 11 */ Line 12 */ case y: System.out.print("0 "); /*
wrapper classes auto Line 13 */
} case x-1: System.out.print("1 "); /*
}
case x: System.out.print("2 "); /*

boxing } Compilation fails at line


NewQB } 012 012122 fails at line 11 12. 0 0 1

Given:

int x = 0;
int y = 10;
Control do {
structures y--;
wrapper ++x;
classes auto } while (x < 5);
boxing System.out.print(x + "," + y);
NewQB What is the result? 5,6 5,5 6,5 6,6 0 1 0

What is the output :

class Test{
public static void main(String[] args) {
int a=5,b=10,c=1;
if(a>c){
System.out.println("success");
Control }
structures else{
wrapper break;
classes auto }
boxing } compiler none of the
NewQB } success runtime error error listed options 0 0 1
Consider the following code and choose the

correct output:
public class Test{
public static void main(String[] args) {
int x = 0;
int y = 10;
do {
Control y--;
structures ++x;
wrapper } while (x < 5);
classes auto System.out.print(x + "," + y);
boxing }
NewQB } 5,6 5,5 6,5 6,6 0 1 0
0
0

0
0
tall short short very short average 0 1 0 0

Compiles but
Compilation error at run time
System.out.println(number); }} error 1515 255 0 0 1 0

Compilation
j=0 j=1 fails 0 0 0 1

Person[] p = Person p[][] =


Which of the following statements about new Person new Person
arrays is syntactically wrong? [5]; Person p[5]; Person[] p []; [2][]; 0 1 0 0

What will be the output of following code?

import java.util.SortedSet;
import java.util.TreeSet;

public class Main {

public static void main(String[] args) {


TreeSet<String> tSet = new
TreeSet<String>();

Consider the following code and choose the


Control correct option:
structures class Test{
wrapper public static void main(String args[]){
classes auto int l=7; Compiles but
boxing Long L = (Long)l; Compilation error at run None of the
NewQB System.out.println(L); }} 7 error time listed options 0 1 0 0

Given:

double height = 5.5;


Control structures if(height-- >= 5.0)
wrapper classes auto System.out.print("tall "); if(--height >= 4.0) System.out.print("average "); if(height-- >= 3.0) System.out.print("short "); else
boxing NewQB System.out.print("very short ");
}
What would be the Result? tall

Control structures Consider the following code and choose the


wrapper classes auto correct option:
boxing NewQB class Test{
public static void main(String args[]){ String hexa = "0XFF";
int number = Integer.decode(hexa);

Control structures Consider the following code and choose the


wrapper classes auto correct option: int i = l, j = -1; switch (i)
boxing NewQB {
case 0, 1: j = 1; case 2: j = 2; default: j = 0;
}
System.out.println("j = " + j); j = -1

Control
structures wrapper classes auto boxing NewQB

import java.util.*;
class I
{

public static void main (String[] args)


{
Control structures +","); Object i = new ArrayList().iterator();
wrapper classes auto System.out.print((i instanceof List)+","); System.out.print((i instanceof Iterator)

System.out.print(i instanceof ListIterator);

boxing } Prints: false, Prints: false, Prints: false, Prints: false,


NewQB } false, false false, true true, false true, true 0 0 1 0

Given:

public static void test(String str) {


int check = 4;
if (check = str.length()) {
System.out.print(str.charAt(check -= 1) +", ");
} else {
System.out.print(str.charAt(0) + ", ");
}
Control }
structures and the invocation:
wrapper test("four");
classes auto test("tee"); An exception
boxing test("to"); Compilation is thrown at
NewQB What is the result? r, t, t, r, e, o, fails. runtime. 0 0 1 0

What will be the output of the program?

Control int x = 3;
structures int y = 1;
wrapper if (x = y) /* Line 3 */
classes auto { The code
boxing System.out.println("x =" + x); Compilation runs with no
NewQB } x=1 x=3 fails. output. 0 0 1 0
tSet.add("1");
tSet.add("2");
tSet.add("3");
tSet.add("4");
tSet.add("5");
Control SortedSet sortedSet = ("3");
structures System.out.println("Head Set Contains : " +
wrapper sortedSet);
classes auto }
boxing } What is the missing method in the code to
NewQB 0.. get the head set of the tree set? tSet.headSet tset.headset headSet HeadSet 1 0 0 0
0

1
0

0
Consider the following code and choose the
correct output:
class Test{

What does the following code fragment write


to the monitor?

System.out.println("the prize.");
You win the You lose the
What does the code fragment prints? prize prize. You win You lose 1 0 0 0

The Map
The return interface
type of the extends the All keys in a
Which statements are true about maps? values() in the original Collection map are
(Choose TWO) method is set map interface unique 0 0.5 0 0.5 0

TreeMap HashSet Vector LinkedList ArrayList 0 0 0 1 0

you have to object to a


make use of file, you use
the class the class
CharacterOut ObjectFileWri
Choose TWO correct options: putStream. ter 0.5 0.5 0 0

M.S.Dhoni
Sachin Virat
M.S.Dhoni Kohli Virat Kohli all of these 1 0 0 0

An overflow
error can only A loop may
Which of the following statements is TRUE occur in a have multiple
regarding a Java loop? loop exit points 0 0 1 0

1 ,3 and 5 2 and 4 3 and 5 4 and 6 1 0 0 0

Exception_ha
ndling_NewQ B Which are true with respect to finally block? block is block will be
(Choose THREE) optional. executed. 0.25 0.25 0.25 0
public static void main(String args[]){
int num=3; switch(num){
default :{
Control System.out.print("default");}
structures case 1: case 3: case 4: {
wrapper System.out.println("apple"); break;}
classes auto case 2: case 5: {
boxing System.out.println("black berry"); }break; } compilation
NewQB }} apple default apple error default 1 0 0
Consider the following code and choose the

correct option:
Control class Test{
structures public static void main(String args[]){
wrapper Long L = null; long l = L;
classes auto System.out.println(L); Compiles but
boxing System.out.println(l); Compilation error at run
NewQB }} null 0 error time 0 null 0 0 1
Control structures int sum = 21;
wrapper classes auto if ( sum != 20 ) System.out.print("You win "); else
boxing NewQB System.out.print("You lose ");

Control structures wrapper classes auto boxing NewQB Changes All Map implementati ons keep the keys sorted
made in the Set view returned by keySet() will be reflected

Control Which collection implementation is suitable for maintaining an ordered sequence of objects, when objects are frequently inserted in and removed from the middle of the sequence?
structures wrapper
classes auto boxing
NewQB

Control OutputStrea To write


m is the abstract characters to an
superclass of Subclasses outputstream, To write an

structures all classes of the class


wrapper classes auto that represent an Reader are used to read

boxing outputstream character


NewQB of bytes. streams.
Control structures What is the output :
wrapper classes auto class One{
boxing NewQB public static void main(String[] args) {
int a=100; if(a>10) System.out.println("M.S.Dhoni"); else if(a>20) System.out.println("Sachin");
else if(a>30) System.out.println("Virat Kohli");}
}

Control structures wrapper classes auto boxing A continue If a variable


NewQB statement doesn’t transfer control to the test statement of the for of type int overflows during the execution of a loop, it will cause an exception
loop

Control structures switch(x)


wrapper classes auto {
boxing NewQB default: System.out.println("Hello");
}
Which of the following are acceptable types for x?
1.byte
2.long
3.char
4.float
5.Short
6.Long
Used to release the resources which are obtained in try block. When an finally block will When no exception occurs then complete try block and finally block will execute but no catch block
exception occurs then a part of never execute will execute.
try block will execute one when no
appropriate catch block exceptions are
Writing finally and finally there.
0.5 0

1 0

0.25
0

quence?
ock and finally block will execute but no catch block
A compile
time error
indicating

" + i);
Exception_ha }
ndling_NewQ B }
} 0 0 0 1

Exception_ha An exception
ndling_NewQ B is thrown at
true Not true runtime. none 1 0 0 0

Both wait()
The wait() The notify() and notify()
method is method is must be
Exception_ha overloaded to sleep overloaded to called from a
ndling_NewQ B Which of the following statements are true? accept a duration accept a synchronized
(Choose TWO) duration expires. duration context. 0 0.33 0.33 0

The program
that a will print will print
RuntimeExce Hello world, Hello world,
What will happen when you attempt to A run time Clean compile Clean compile but no output at runtime
compile and run the following code? public class Bground extends Thread{ public static void error indicating and at run time
main(String argv[]){ that no run the values 0 to
Bground b = new Bground(); method is 9 are printed
b.run(); defined for the out
} Thread class
public void start(){
for (int i = 0; i <10; i++){ System.out.println("Value of i = that no run
method is defined for the Thread class

Given:
public void testIfA() { if (testIfB("True")) { System.out.println("True");
} else {
System.out.println("Not true");
}
}
public Boolean testIfB(String str) {
return Boolean.valueOf(str);
}
What is the result when method testIfA is invoked?

Deadlock will not occur if wait()/notify() is used A thread will


resume execution as soon as its

public class MyProgram


{
public static void throwit()
{
throw new RuntimeException();
}
public static void main(String args[])
{
try
{
System.out.println("Hello world "); The program
throwit(); System.out.println("Done with try will print
block "); Hello world,
} then will print The program
finally

{ ption has then will print then will print


System.out.println("Finally executing occurred, that a Finally
"); then will print RuntimeExce executing,
} Done with try ption has then will print
} block, and occurred, and that a
Exception_ha } The program then will print then will print RuntimeExce
ndling_NewQ which answer most closely indicates the will not Finally Finally ption has
B behavior of the program? compile. executing. executing. occurred. 0 0 0 1
If a method is capable of causing an
exception that it does not handle, it must
Exception_ha specify this behavior using throws so that
ndling_NewQ callers of the method can guard themselves
B against such Exception false true 0 1
A) Checked Exception must be explicity

caught or propagated to the calling method


B) If runtime system can not find an
Exception_ha appropriate method to handle the exception,
ndling_NewQ then the runtime system terminates and uses Only A is Only B is Bothe A and Both A and B
B the default exception handler. TRUE TRUE B is TRUE is FALSE 0 0 1 0

public class RTExcept


{
public static void throwit ()
{
System.out.print("throwit ");
throw new RuntimeException();
}

public static void main(String [] args)


{
try
{
System.out.print("hello ");
throwit();
}

catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
} hello throwit
Exception_ha System.out.println("after "); hello throwit RuntimeExce
ndling_NewQ } caught finally hello throwit ption caught Compilation
B } after caught after fails 1 0 0
0 1

0.33
0 1

1 0
0
Exception_ha Cannot
ndling_NewQ B Compilation determine prints 12 12
Error output. 12 12 0 0 0 1

What is wrong with the following code?

A try block
cannot be A finally block
followed by must always
Exception_ha RuntimeExce both a catch An empty A catch block follow one or
ndling_NewQ B ption in a and a finally catch block is cannot follow more catch
} throws clause block not allowed a finally block blocks 0 0 0 1 0

Exception_ha test test


ndling_NewQ B test runtime exception end exception
runtime end end 0 0 0 1

X run = new Thread t =


Exception_ha } Thread t = Thread t = X(); Thread t new

class s implements Runnable


{
int x, y;
public void run()
{

for(int i = 0; i < 1000; i++)


synchronized(this)
{

x = 12;
y = 12;
}

System.out.print(x + " " + y + " ");


}
public static void main(String args[])
{
s run = new s();
Thread t1 = new Thread(run); Thread t2 = new Thread(run); t1.start();
t2.start();
}

} What is the output? DeadLock


Class MyException extends Exception{} Since the method foo() does not catch the exception generated by the method baz(),it must declare the
public class Test{ public void foo() { try {
bar();
} finally {
baz();
} catch(MyException e) {}
}
public void bar() throws MyException {
throw new MyException();
}
public void baz() throws RuntimeException {
throw new RuntimeException();
}

Consider the following code and choose the


correct option:
class Test{
static void test() throws RuntimeException {
try { System.out.print("test ");
throw new RuntimeException();
} catch (Exception ex) { System.out.print
("exception "); }
} public static void main(String[] args) {
try { test(); } catch (RuntimeException ex) { System.out.print("runtime "); } System.out.
print("end"); } } test end

A method

declaring that
it throws a
If an An overriding certain Finally blocks
exception is method must exception are executed
not caught in declare that it The main() class may if,an
a method,the throws the method of a throw exception
method will same program can instances of gets thrown
terminate and exception declare that it any subclass while inside
Exception_ha normal classes as throws of that the
ndling_NewQ execution will the method it checked exception correspondin
B Choose TWO correct options: resume overrides exception class g try block 0 0 0.5 0.5 0

Which four can be thrown using the throw

statement?

1.Error

2.Event
3.Object
Exception_ha 4.Throwable
ndling_NewQ 5.Exception
B 6.RuntimeException 1, 2, 3 and 4 2, 3, 4 and 5 1, 4, 5 and 6 2, 4, 5 and 6 0 0 1 0

class X implements Runnable

{
public static void main(String args[])
{
/* Missing code? */
}
public void run() {}
ndling_NewQ Which of the following line of code is suitable new Thread new Thread = new Thread Thread(); x.
B to start a thread ? (X); (X); t.start(); (run); t.start(); run(); 0 0 1
Given:

class X { public void foo() { System.out.print


("X "); } }

public class SubB extends X {

public void foo() throws RuntimeException {


super.foo();
if (true) throw new RuntimeException();
System.out.print("B ");
}
public static void main(String[] args) { X, followed
new SubB().foo(); No output, by an
Exception_ha } X, followed and an Exception,
ndling_NewQ } by an Exception is followed by
B What is the result? Exception. thrown. B. none 1 0 0
1

1 0

1
0.5 0

0
0
What will the output of following code?

Exception_ha

try
{
int x = 0;
int y = 5 / x;
}

catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
Exception_ha System.out.println(" Arithmetic Exception");
ndling_NewQ } compilation ArithmeticExc
B System.out.println("finished"); finished Exception fails eption 0 0
Exception_ha
ndling_NewQ
B Which of the following methods are static? start() join() yield() sleep() 0 0

static

methods can static


static be called methods do
methods are using an not have
difficult to object static direct access
maintain, reference to methods are to non-static
because you an object of always methods
can not the class in public, which are
Exception_ha change their which this because they defined
ndling_NewQ Which of the following statements regarding implementati method is are defined at inside the
B static methods are correct? (2 answers) on. defined. class-level. same class. 0 0.5

Consider the following code and choose the exit


correct option: RuntimeExce
class Test{
static void display(){
throw new RuntimeException();
} public static void main(String args[]){
try{display();
}catch(Exception e){ throw new
NullPointerException();}
finally{try{ display();
}catch(NullPointerException e){ System.

ndling_NewQ out.println("caught");} ption thrown Compilation


B finally{ System.out.println("exit");}}}} caught exit exit at run time fails 0 0

class Test{

public static void main(String[] args){


try{
Integer.parseInt("1.0");
}
catch(Exception e){
System.out.println("Exception occurred");
}
catch(RuntimeException ex){
System.out.println("RuntimeException");
} Exception
Exception_ha }} occurred
ndling_NewQ consider the code above & select the proper Exception RuntimeExce RuntimeExce does not
B output from the options. occurred ption ption compile 0 0

Which three of the following are methods of

the Object class?

1.notify();

2.notifyAll();
3.isInterrupted();
4.synchronized();
5.interrupt();
Exception_ha 6.wait(long msecs);
ndling_NewQ 7.sleep(long msecs);
B 8.yield(); 1, 2, 4 2, 4, 5 1, 2, 6 2, 3, 4 0 0
In the given code snippet

try { int a = Integer.parseInt("one"); }


what is used to create an appropriate catch
block? (Choose all that apply.)
A. ClassCastException
Exception_ha B. IllegalStateException
ndling_NewQ C. NumberFormatException ClassCastEx NumberForm IllegalStateEx IllegalArgume
B D. IllegalArgumentException ception atException ception ntException 0 0.5
class Trial{

public static void main(String[] args){


try{
System.out.println("One");
int y = 2 / 0;
System.out.println("Two");
}
catch(RuntimeException ex){
System.out.println("Catch");
}
finally{
Exception_ha System.out.println("Finally");
ndling_NewQ } One Two One Catch One Two
B }} Catch Finally One Catch Finally Catch 0 0
1 0

0.5 0.5

0 0.5

1 0

0 1

1 0

0 0.5

1 0
Which digit,and in what order,will be printed
when the following program is run?

X run = new Thread t =


Exception_ha X(); Thread t Thread t = new Thread t =

Public class MyClass {


public static void main(String[] args) {
int k=0;
try {
int i=5/k;
}
catch(ArithmeticException e) { System.out.println("1");
}
catch(RuntimeException e) { System.out.println("2"); return;
}
catch(Exception e) { System.out.println("3");
}

finally{
System.out.println("4");
} The program The program The program The program
Exception_ha System.out.println("5"); The program will only print will only print will only print will only print
ndling_NewQ } will only print 1 and 4 in 1,2 and 4 in 1 ,4 and 5 in 1,2,4 and 5 in
B } 5 order order order order 0 0 0 1

We cannot

class Trial{ have a try


public static void main(String[] args){ We cannot block block
Exception_ha try{ have a try without a
ndling_NewQ System.out.println("Java is portable"); Java is block without catch / finally Nothing is
B }}} portable a catch block block diaplayed 0 0 1 0

class Animal { public String noise() { return

"peep"; } }
class Dog extends Animal {
public String noise() { return "bark"; }
}
class Cat extends Animal {
public String noise() { return "meow"; }
}
class try1{
public static void main(String[] args){
Animal animal = new Dog();
Cat cat = (Cat)animal;
System.out.println(cat.noise());
Exception_ha }} An exception
ndling_NewQ consider the code above & select the proper Compilation is thrown at
B output from the options. bark meow fails runtime. peep 0 0 0 1

Given:
class X implements Runnable
{

public static void main(String args[])


{
/* Some code */
}
public void run() {}
}
ndling_NewQ Which of the following line of code is suitable = new Thread new Thread Thread(); x. new Thread
B to start a thread ? (run); t.start(); (X); run(); (X); t.start(); 1 0 0 0

If a class has Variables can be protected from


synchronized

code, concurrent
multiple access
A static threads can problems by When a
method still access marking them thread
Exception_ha cannot be the with the sleeps, it
ndling_NewQ synchronized nonsynchroni synchronized releases its
B Which statement is true? . zed code. keyword. locks 0 1 0 0

Consider the following code and choose the


correct option:
class Test{
static void display(){
throw new RuntimeException();
}

public static void main(String args[]){


try{display();
Exception_ha }catch(Exception e){ } Compiles but
ndling_NewQ catch(RuntimeException re){} Compiles and Compilation exception at
B finally{System.out.println("exit");}}} exit no output fails runtime 0 0 1 0

Given:
public class ExceptionTest
{

class TestException extends Exception {}


public void runTest() throws TestException
{}
public void test() /* Line X */
{

runTest();
}
Exception_ha } throws
ndling_NewQ At Line X, which code is necessary to make No code is throws throw RuntimeExce
B the code compile? necessary Exception Exception ption 0 1 0
Implement
java.lang. Implement Extend java. Implement
Runnable Extend java. java.lang. lang. java.lang.
and lang.Thread Thread and Runnable Thread and
Exception_ha implement and override implement and override implement
ndling_NewQ Which two can be used to create a new the run() the run() the start() the start() the run()
B Thread? method. method. method. method. method. 0.5 0.5 0
0 1 0

1 0

0 1 0

0 0

0 0

1 0
0

0 0
An Error that
might be
thrown in a
Multiple catch method must starts to

Consider the following code:

Exception_ha
ndling_NewQ B
not compile. Found file exception. found. 1 0 0 0

Exception_ha Error must be must be

Except in
case of VM shutdown, if a try block

Exception_ha A try statements be declared execute, a


statement can catch the as thrown by correspondin
Exception_ha

must have at same class of that method, g finally block


least one exception or be handled will always
ndling_NewQ correspondin more than within that start to
B Choose the correct option: g catch block once. method. execute. 0 0 0 1

class PropagateException{

public static void main(String[] args){


try{
method();
System.out.println("method() called");
}
catch(ArithmeticException ex){
System.out.println("Arithmetic Exception");
}
catch(RuntimeException re){
System.out.println("Runtime Exception");
}}
static void method(){
int y = 2 / 0; Arithmetic
Exception_ha }} Exception
ndling_NewQ consider the code above & select the proper Arithmetic Runtime Runtime compilation
B output from the options. Exception Exception Exception error 1 0 0 0

Given:

static void test() {


try {
String x = null;
System.out.print(x.toString() + " ");
}
finally { System.out.print("finally "); }
}
public static void main(String[] args) {
try { test(); }
catch (Exception ex) { System.out.print
Exception_ha ("exception "); }
ndling_NewQ } Compilation finally
B What is the result? null fails. exception finally 0 0 1 0
Given two programs:

1. package pkgA;
2. public class Abc {
3. int a = 5;
4. protected int b = 6;
5. public int c = 7;
6. }

3. package pkgB;

4. import pkgA.*;
5. public class Def {
6. public static void main(String[] args) {
7. Abc f = new Abc();
8. System.out.print(" " + f.a);
9. System.out.print(" " + f.b);
10. System.out.print(" " + f.c);
11. } Compilation Compilation Compilation
Exception_ha 12. } fails with an fails with an fails with an
ndling_NewQ What is the result when the second program 5 followed by error on line error on line error on line
B is run? (Choose all that apply) 567 an exception 7 8 9 0 0 0 0.5 0.5

System.out.print("Start ");
try
{

System.out.print("Hello world");
throw new FileNotFoundException();
}

System.out.print(" Catch Here "); /* Line 7 */


catch(EOFException e)
{

System.out.print("End of file exception");


}
catch(FileNotFoundException e)
{
System.out.print("File not found"); Code output:
}

given that EOFException and Code output: Code output: Start Hello
FileNotFoundException are both subclasses Start Hello Start Hello world Catch
of IOException. If this block of code is pasted The code will world File Not world End of Here File not
in a method, choose the best option.

catch(X x) Any statement Any


can catch that can throw statement that can throw an Exception
subclasses of The Error an

X where X is class is a
ndling_NewQ a subclass of RuntimeExce enclosed in a enclosed in a
B Which of the following statements is true? Exception. ption. try block. try block. 1 0 0 0
Consider the following code and choose the
Exception_ha correct option:
ndling_NewQ int array[] = new int[10]; compiles does not none of the
B array[-1] = 0; successfully compile runtime error listed options 0 0 1 0
0
1

0.5 0.5

0
0
What will be the output of the program?

arguments, will throw an will simply


Exception_ha the program ArrayIndexO print the
ndling_NewQ B will produce utOfBoundsE given
}}} no output xception argument 0 0.5 0 0
Which can appropriately be thrown by a programmer using Java SE
technology to
create ClassCastEx NullPointerEx NoClassDefF NumberForm
a desktop application? ception ception oundError atException 0 0 0 1
ArrayIndexO NullPointerEx
utOfBoundsE
Which of the following is a checked Arithmetic
exception? Exception IOException ception xception 0 1 0 0
public class RTExcept
{
public static void throwit ()
{
System.out.print("throwit ");
throw new RuntimeException();
}

public static void main(String [] args)


{
try
{
System.out.print("hello ");
throwit();
}

catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
} hello throwit
Exception_ha System.out.println("after "); RuntimeExce hello throwit
ndling_NewQ } hello throwit Compilation ption caught caught finally
B } caught fails after after 0 0 0 1
Exception_ha What is the keyword to use when the access

ndling_NewQ of a method has to be restricted to only one


B thread at a time volatile synchronized final private 0 1 0 0
Consider the following code and choose the

correct option:
class Test{
public static void parse(String str) {
try { int num = Integer.parseInt(str);
} catch (NumberFormatException nfe) {
num = 0; } finally { System.out.println NumberForm
Exception_ha (num); atException ParseExcepti
ndling_NewQ } } public static void main(String[] args) { thrown at Compilation on thrown at
B parse("one"); } runtime fails runtime 0 0 1 0
public static void parse(String str) {

try {
float f = Float.parseFloat(str);
} catch (NumberFormatException nfe) {
f = 0;
} finally { A
System.out.println(f); A NumberForm
} ParseExcepti atException
} on is thrown is thrown by
Exception_ha public static void main(String[] args) { by the parse the parse
ndling_NewQ parse("invalid"); Compilation method at method at
B } fails runtime. runtime. 0 1 0
Given the following program,which statements If run with one arguments, If run with one arguments, the program will print the given argument followed by
are true? (Choose TWO) Public class Exception { If run with no If run with no The program the program "The end"
public static void main(String[] args) { arguments,
try { the program will produce "The end"
if(args.length == 0) return; System.out.println(args[0]);
}finally { System.out.println("The end");

Exception_ha
ndling_NewQ B
Exception_ha ndling_NewQ B

Given:

11. class A {
12. public void process() { System.out.print
("A,"); }
13. class B extends A {
14. public void process() throws IOException {
15. super.process();
16. System.out.print("B,");
17. throw new IOException();
18. }
19. public static void main(String[] args) {
20. try { new B().process(); }
21. catch (IOException e) { System.out.println Compilation Compilation
Exception_ha ("Exception"); } fails because fails because
ndling_NewQ 22. } A,B, of an error in of an error in
B What is the result? Exception Exception line 20. line 14. 0 0 0 1
The The notify()

notifyAll() method
method must To call The notify() causes a
be called sleep(), a method is thread to
Exception_ha from a thread must defined in immediately
ndling_NewQ synchronized own the lock class java. release its
B Which statement is true? context on the object lang.Thread locks. 1 0 0 0

class Trial{

public static void main(String[] args){


try{
System.out.println("Try Block");
}
finally{
Exception_ha System.out.println("Finally Block");
ndling_NewQ } Try Block Finally Block
B }} Try Block Finally Block Finally Block Try Block 0 1 0
0.5

0 1

0 0
0 1

0 0

1 0

0
nt the given argument followed by

0 1
0 0

0
consider the code & choose the correct
output:
class Threads2 implements Runnable {

End of End of
method. java. method. run.
java.lang. run java.lang. lang. java.lang.
RuntimeExce RuntimeExce RuntimeExce RuntimeExce
ption: ption: ption: ption:
} Problem Problem Problem Problem

The exceptions for which the compiler doesn’t Checked Unchecked


enforce the handle or declare rule exceptions exceptions Exception all of these

Exception_ha Compiles but


ndling_NewQ B Compilation error at run time
error

Exception_ha An exception
ndling_NewQ B Compilation is thrown at
Which statement is true? fails. runtime.

Exception_ha Compiles but


ndling_NewQ B Compilation exception at
exit fails runtime

An object is
deleted as
soon as there The finilize()
are no more
Garbage_Col Which statements describe guaranteed references access it
lection_New behaviour of the garbage collection and that denote through a
QB0 finalization mechanisms? (Choose TWO) the object reference.

Garbage_Col
lection_New
QB B C D

Garbage_Col Runtime.
lection_New Which of the following allows a programmer to getRuntime(). destroy an
QB destroy an object x? x.delete() x.finalize() gc() object.

Garbage_Col
lection_New after line 11 runs, how many objects are
QB eligible for garbage collection? 1 2 3
Garbage_Col
lection_New after line 11 runs, how many objects are
QB eligible for garbage collection? 1 2 3
Exception_ha ndling_NewQ public void run() {
B System.out.println("run.");
Exception_ha ndling_NewQ throw new RuntimeException("Problem");
B }
public static void main(String[] args) { Thread t = new Thread(new Threads2()); t.start();
System.out.println("End of method.");
}

Consider the code below & select the correct


ouput from the options: public class Test{ Integer i;
int x; Test(int y){ x=i+y;
System.out.println(x);
}
public static void main(String[] args) {
new Test(new Integer(5));
}} 5

Given: Declaring the


public class TestSeven extends Thread { Synchronizin doThings()
private static int x;
public synchronized void doThings() {
int current = x;
current++;
x = current;
}

public void run() { g the run() method as


doThings(); method would make the class static would make the class thread- safe.
} thread-safe.
}

Consider the following code and choose the


correct option:
class Test{
static void display(){
throw new RuntimeException();
} public static void main(String args[]){ try{ display(); }catch(Exception e){ throw new NullPointerException();} finally{try{ display();
}catch(NullPointerException e){ System. out.println("caught");}
System.out.println("exit");}}} caught exit

An object will
not be garbage collected as
The finalize() long as it

method will method will


never be
eventually be called more
called on than once on
every object an object
Which statement is true?
A. A class's finalize() method CANNOT be invoked explicitly.
B. super.finalize() is called implicitly by any overriding finalize() method.
C. The finalize() method for a given object is called no more than once by the garbage collector.
D. The order in which finalize() is called on
two objects is based on the order in which the two
objects became finalizable. A

Only the
garbage collection system can

class X2
{
public X2 x;
public static void main(String [] args)
{
X2 x2 = new X2(); /* Line 6 */
X2 x3 = new X2(); /* Line 7 */
x2.x = x3;
x3.x = x2;
x2 = new X2();
x3 = x2; /* Line 11 */
}
}
ethod. java. method. run.
java.lang.
meExce RuntimeExce
ption:
Problem 0 0 0 1

all of these 0 1 0 0

0 0 1 0

An exception
is thrown at
runtime. 0 0 1 0

Compiles but
exception at
runtime 0 0 0 1

access it use a mark


through a and sweep
reference. algorithm 0 0 0.5 0.5

0 0 1 0

etRuntime(). destroy an
0 0 0 1

0 0 1 0
0 0 1 0

art();

ings()

method as
static would make the class thread- safe.

lly{try{ display();

object will
rbage collected as
lize() long as it

possible for a The garbage


live thread to collector will
y be called more
than once on
an object

Only the
llection system can
Garbage_Col
lection_New none of the
QB Thi i java listed options 0 0 0 1

Call System.
Set all gc() passing
references to in a reference

Given :
public class MainOne {
public static void main(String args[]) { String str = "this is java"; System.out.println(removeChar(str,'s'));

public static String removeChar(String s, char c) {


String r = "";
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != c)
r += s.charAt(i);

}
return r;
}

} What would be the result? This is java Thi is java This i java
Garbage_Col the object to to the object Garbage
lection_New
Garbage_Col
lection_New new values to be collection
How can you force garbage collection of an (null, for garbage Call System. Call Runtime. cannot be
QB object? example). collected gc() gc(). forced 0 0 0

Consider the following code and choose the


correct option:
public class X
{

public static void main(String [] args)


{
X x = new X();
X x2 = m1(x); /* Line 6 */ X x4 = new X();
x2 = x4; /* Line 8 */
doComplexStuff(); }

static X m1(X mx) {


mx = new X();
Garbage_Col return mx; }}
lection_New After line 8 runs. how many objects are
QB eligible for garbage collection? 1 2 3 0 1 0
interface interface_1 {

void f1();
}
class Class_1 implements interface_1 {
void f1() {
System.out.println("From F1 funtion in
Class_1 Class");
}
}
public class Demo1 {
Inheritance_I public static void main(String args[]) {
nterfaces_Ab Class_1 o11 = new Class_1(); From F1
stract o11.f1(); function in Create an
Classes_New } Class_1 Compile time object for Runtime
QB } Class error Interface only Error 0 1 0
Given:
class A {
final void meth() { System.out.println("This is a final
method.");
}

}
class B extends A {
void meth() {
System.out.println("Illegal!");
}
}
class MyClass8{
public static void main(String[] args) {
A a = new A();
Inheritance_I a.meth();
nterfaces_Ab B b= new B(); This is a final
stract b.meth(); This is a final method illegal Some
Classes_New } method Some error Compil ation error

QB }What would be the result? illegal message error message 0 0 1

Which Man class properly represents the

relationship "Man has a best friend who is a


Inheritance_I Dog"?
nterfaces_Ab A)class Man extends Dog { }
stract B)class Man implements Dog { }
Classes_New C)class Man { private BestFriend dog; }
QB D)class Man { private Dog bestFriend; } A B C D 0 0 0
1 0
0 1

1
What will be the output of the program?

Compilation
4, 5 5, 4 fails 0 0 0 1

Compilation
47 7 0 error 47 47 47 0 0 0 1

Which code, inserted at line 6, will cause a


java.lang.ClassCastException? B b=c; A a2=(B)c; C c2=(C)(B)c; A a1=(Test)c; 0 0 0 1

Classes_New /* Missing Statements ? */ getArea(int r); double getVol rad * rad * getArea(int
QB Select the correct missing statements. } (int x, int y); } 3.14; } } rad); } 0 0 1 0

Compiles but
Compilation error at runtime
sum of byte 7 error sum of int7 0 0 1 0
Compiles but
Compilation error at runtime
sum of byte 7 error sum of int7 0 0 1 0
class SuperClass
{
public Integer getLength()
{
return new Integer(4);
}
}

public class SubClass extends SuperClass


{
public Long getLength()
{
return new Long(5);
}
public static void main(String[] args)
{
Inheritance_I SuperClass sp = new SuperClass();
nterfaces_Ab stract SubClass sb = new SubClass(); System.out.println( sp.getLength().toString() + "," + sub.
Classes_New QB getLength().toString() );
}
} 4, 4

Inheritance_I Consider the code below & select the correct


nterfaces_Ab stract ouput from the options:
Classes_New QB abstract class Ab{ public int getN(){return 0;}}
class Bc extends Ab{ public int getN(){return
7;}}
class Cd extends Bc { public int getN(){return
47;}}
class Test{
public static void main(String[] args) { Cd cd=new Cd();
Bc bc=new Cd(); Ab ab=new Cd(); System.out.println(cd.getN()+" "+
bc.getN()+" "+ab.getN()); }} 000

Inheritance_I interface A{}


nterfaces_Ab stract class B implements A{}
Classes_New QB class C extends B{}
public class Test extends C{
public static void main(String[] args) { C c=new C();
/* Line6 */}}

Given :

What would be the result of compiling and


running the following program?
// Filename: MyClass.java
public class MyClass {
public static void main(String[] args) {
C c = new C();
System.out.println(c.max(13, 29));
}
}
class A {
int max(int x, int y) { if (x>y) return x; else The code will
return y; } fail to compile
} because the
class B extends A{ max()
int max(int x, int y) { return super.max(y, x) - method in B The code will
10; } passes the fail to compile
Inheritance_I } arguments in because a
nterfaces_Ab class C extends B { the call call to a The code will The code will
stract int max(int x, int y) { return super.max(x+10, super.max(y, max() compile and compile and
Classes_New y+10); } x) in the method is print 23, print 29,
QB } wrong order. ambiguous. when run. when run. 0 0 0

The concept of multiple inheritance is

implemented in Java by

Inheritance_I (A) extending two or more classes

nterfaces_Ab (B) extending one class and implementing


stract one or more interfaces
Classes_New (C) implementing two or more interfaces
QB (D) all of these (A) (A) & (C) (D) (B) & (C) 0 0 0
Given:

interface DoMath abstract class


{ AllMath
double getArea(int r); implements
} DoMath,
interface MathPlus class AllMath interface MathPlus { class AllMath
Inheritance_I { extends AllMath public double implements
nterfaces_Ab double getVolume(int b, int h); DoMath { implements getArea(int MathPlus {
stract } double MathPlus { rad) { return double
Inheritance_I Consider the following code and choose the
nterfaces_Ab stract correct option:
Classes_New QB class A{
void display(byte a, byte b){ System.out.println("sum of byte"+(a+b)); } void display(int a, int b){ System.out.println("sum of int"+(a+b)); } public static void main(String[] args) {
new A().display(3, 4); }}
1

0
1

1
run time error generic noise bark compile error 1 0 0

sal details compilation per details


sal details per details error sal details 0 0 0 1

Compiles but
Compilation error at run time
3 error 9 0 1 0 0

No—a
No—a variable must
Given: variable must always be an
public static void main( String[] args ) always be an object No—a
{ SomeInterface x; ... } object reference variable must class
Can an interface name be used as the type of reference type or a always be a implements
a variable type primitive type primitive type the interface 0 0 0 1

Compiles but
compilation error at runtime
3 4 error 0 0 1 0

The B class The The The The


is a subclass statement b. statement a.j statement a. statement b.i
of A. f(); is legal = 5; is legal. g(); is legal = 3; is legal. 0.333333 0.333333 0 0.333333

final double
circumferenc protected int e = 2
int total = * Math. CODE = int AREA = r public static
total + r + s; PI * r; 31337; * s; MAIN = 15; 0 0.5 0
Consider the following code and choose the

correct option:
interface Output{
void display();
void show();
Inheritance_I }
nterfaces_Ab class Screen implements Output{
stract void display(){ System.out.println("display"); } Compiles but
Classes_New public static void main(String[] args) { Compilation error at run Runs but no
QB new Screen().display();}} display error time output 0 1
Inheritance_I nterfaces_Ab class Animal {
stract Classes_New QB void makeNoise() {System.out.println("generic noise"); }
}
class Dog extends Animal {
void makeNoise() {System.out.println("bark");
}
void playDead() { System.out.println("roll over"); }
}
class CastTest2 {
public static void main(String [] args) { Dog a = (Dog) new Animal(); a.makeNoise();
}
}
consider the code above & select the proper output from the options.

Inheritance_I nterfaces_Ab Consider the following code and choose the


stract Classes_New QB correct option: interface employee{ void saldetails(); void perdetails();
}
abstract class perEmp implements employee{ public void perdetails(){ System.out.println("per details"); }}
class Programmer extends perEmp{
public void saldetails(){ perdetails(); System.out.println("sal details"); }
public static void main(String[] args) { perEmp emp=new Programmer(); emp.saldetails(); }}

Inheritance_I nterfaces_Ab Consider the code below & select the correct
stract Classes_New QB ouput from the options:
class A{
static int sq(int n){
return n*n; }}
public class Test extends A{
static int sq(int n){
return super.sq(n); }
public static void main(String[] args) { System.out.println(new Test().sq(3)); }}

Inheritance_I nterfaces_Ab stract Classes_New QB Yes—the


variable can refer to any object whose

Inheritance_I nterfaces_Ab Consider the following code and choose the


stract Classes_New QB correct option:
interface A{ int i=3;} interface B{ int i=4;}
class Test implements A,B{
public static void main(String[] args) { System.out.println(i);
}
}

Inheritance_I nterfaces_Ab Given the following classes and declarations,


stract Classes_New QB which statements are true?
// Classes class A { private int i;
public void f() { /* ... */ }
public void g() { /* ... */ }
}
class B extends A{
public int j;
public void g() { /* ... */ }
}
// Declarations: A a = new A(); B b = new B();
Select the three correct answers.
Inheritance_I nterfaces_Ab Which declaration can be inserted at (1)
stract Classes_New QB without causing a compilation error?
interface MyConstants {
int r = 42;
int s = 69;
// (1) INSERT CODE HERE
}
0

0 1

0 0

0 1

1 0

0 0.333333 0

0.5 0
0 0
nterfaces_Ab later we must and later we we can use in extends and

What is the output for the following code:

abstract class One{


private abstract void test();
}
class Two extends One{
void test(){
System.out.println("hello");
}}
class Test{
Inheritance_I public static void main(String[] args){
nterfaces_Ab Two obj = new Two();
stract obj.test();
Classes_New } run time compile time
QB } exception error hello hellohello 0 1

Consider the code below & select the correct

ouput from the options:

class Money {

private String country = "Canada";


Inheritance_I public String getC() { return country; } }
nterfaces_Ab class Yen extends Money {
stract public String getC() { return super.country; } Compiles but
Classes_New public static void main(String[] args) { Compilation error at run
QB System.out.print(new Yen().getC() ); } } Canada error time null 0 1
we must use we must use

always always
Inheritance_I extends and implements

stract When we use both implements & extends use must use any order its implements
Classes_New keywords in a single java program then what implements extends not at all a can't be used
QB is the order of keywords to follow? keyword. keyword. problem together 1 0

Consider the code below & select the correct

ouput from the options:


1. public class Mountain {
2. protected int height(int x) { return 0; }
3. }
4. class Alps extends Mountain {
5. // insert code here
6. }
Which five methods, inserted independently at
line 5, will compile? (Choose three.)
Inheritance_I A. public int height(int x) { return 0; }
nterfaces_Ab B. private int height(int x) { return 0; }
stract C. private int height(long x) { return 0; }
Classes_New D. protected long height(long x) { return 0; }
QB E. protected long height(int x) { return 0; } A,B,E A,C,D B,D,E C,D,E 0 1

Given:

interface DeclareStuff {
public static final int Easy = 3;
void doStuff(int t); }
public class TestDeclare implements
DeclareStuff {
public static void main(String [] args) {
int x = 5;
new TestDeclare().doStuff(++x);
}
Inheritance_I void doStuff(int s) {
nterfaces_Ab s += Easy + ++s;
stract System.out.println("s " + s);
Classes_New } Compilation
QB } What is the result? s 14 s 16 s 10 fails. 0 0

Given:

interface A { public void methodA(); }


interface B { public void methodB(); }
interface C extends A,B{ public void
methodC(); } //Line 3 If you define If you define
class D implements B { D e = (D) D e = (D)
public void methodB() { } //Line 5 (new E()), (new E()),
} then e. then e.
class E extends D implements C { //Line 7 methodB() methodB()
Inheritance_I public void methodA() { } invokes the invokes the
nterfaces_Ab public void methodB() { } //Line 9 Compilation version of Compilation version of
stract public void methodC() { } fails, due to methodB() fails, due to methodB()
Classes_New } an error in defined at an error in defined at
QB What would be the result? line 3 line 9 line 7 line 5 0 1

It must be It must be

Inheritance_I used in the used in the


nterfaces_Ab It can only be last first
stract used in the Only one statement of statement of
Classes_New Which of the following statements is true parent's child class the the
QB regarding the super() method? constructor can use it constructor. constructor. 0 0

Consider the following code and choose the

correct option:
interface Output{
void display();
void show();
}
Inheritance_I class Screen implements Output{
nterfaces_Ab void show() {System.out.println("show");}
stract void display(){ System.out.println("display"); } Compiles but
Classes_New public static void main(String[] args) { Compilation error at run Runs but no
QB new Screen().display();}} display error time output 0 1
0 0

0 0

0 0

0 0

0 1

0 0

0 1
0 0
p1 = (ClassB)
p0 = p1; p2 = p4; p3; p1 = p2; 0.5 0 0.5 0

Compiles but
Compilation error at runtime
150 mph error 90 mph 1 0 0 0

Compiles but
Compilation error at runtime
error Hello B 0 0 1 0

Because of
single
inheritance,
have no other Animal can
A class Animal has a subclass Mammal. parent than have only
Which of the following is true: subclasses Animal one subclass 0 1 0 0

compile error 0 0 1 0
Consider the following code and choose the

correct option:
class A{
void display(){ System.out.println("Hello A");
}}
class B extends A{
void display(){
Inheritance_I System.out.println("Hello B"); }}
nterfaces_Ab public class Test {
stract public static void main(String[] args) { Compiles but
Classes_New B b=(B) new A(); Compilation error at
QB b.display(); }} Hello A error Hello B runtime 0 0 0 1

Consider the following code:

// Class declarations: Definitely


class Super {} legal at Definitely
class Sub extends Super {} runtime, but legal at
Inheritance_I // Reference declarations: Legal at the cast runtime, and
nterfaces_Ab Super x; compile time,operator the cast
stract Sub y; but might be (Sub) is not operator
Classes_New Which of the following statements is correct Illegal at illegal at strictly (Sub) is
QB for the code: y = (Sub) x? compile time runtime needed. needed. 0 1 0 0

Inheritance_I nterfaces_Ab Given:


stract Classes_New QB 11. class ClassA {}
12. class ClassB extends ClassA {}
13. class ClassC extends ClassA {}
and:
21. ClassA p0 = new ClassA();
22. ClassB p1 = new ClassB();
23. ClassC p2 = new ClassC();
24. ClassA p3 = new ClassB();
25. ClassA p4 = new ClassC();
Which TWO are valid? (Choose two.)

Inheritance_I nterfaces_Ab Consider the following code and choose the


stract Classes_New QB correct option:
abstract class Car{
abstract void accelerate();
}
class Lamborghini extends Car{
@Override
void accelerate() { System.out.println("90 mph"); } void nitroBooster(){ System.out.print("150 mph"); }
public static void main(String[] args) { Car mycar=new Lamborghini(); Lamborghini lambo=(Lamborghini) mycar; lambo.nitroBooster();}}

Inheritance_I nterfaces_Ab Consider the following code and choose the


stract Classes_New QB correct option:
class A{
void display(){ System.out.println("Hello A");
}}
class B extends A{ void display(){ System.out.println("Hello B"); }} public class Test {
public static void main(String[] args) { A a=new B();
B b= (B)a;
b.display(); }} Hello A

Inheritance_I nterfaces_Ab stract Classes_New QB Because of single inheritance, Mammal can have Because of Because of single inheritance, Mammal can have no siblings.
no single inheritance,
Mammal can
Inheritance_I nterfaces_Ab class Animal {
stract Classes_New QB void makeNoise() {System.out.println("generic noise"); }
}
class Dog extends Animal {
void makeNoise() {System.out.println("bark");
}
void playDead() { System.out.println("roll over"); }
}
class CastTest2 {
public static void main(String [] args) { Animal a = new Dog(); a.makeNoise();
}
}
consider the code above & select the proper
output from the options. run time error generic noise bark

What will be the result when you try to

compile and run the following code?


class Base1 {
Base1() {
int i = 100;
System.out.println(i);
}
}

public class Pri1 extends Base1 {

static int i = 200;

Inheritance_I public static void main(String argv[]) {

nterfaces_Ab Pri1 p = new Pri1();


stract System.out.println(i);
Classes_New } Error at 100 followed
QB } compile time 200 by 200 100 0 0 1 0
Classes_New Foo a = new Foo(); is a subclass statement a.j statement b. statement a.

The code
Compilation Cannot add runs with no
fails. Toppings output. 1 0 0

Compiles but
Compilation error at run timeRuns but no
A error output 0 1 0

private final public static


Which of these field declarations are legal in public int final static int static int int answer =
an interface? (Choose all applicable) answer = 42; answer = 42; answer = 42; int answer; 42; 0.25 0.25 0.25

Given :
Yes—an
Day d; object can be
BirthDay bd = new BirthDay("Raj", 25); assigned to a Yes—any
d = bd; // Line X reference
assigned to a variable of
Where Birthday is a subclass of Day. State variable of the parent
whether the code given at Line X is correct: the object child type. type. 0 0 1

If both a If neither

default constructor,
constructor of this() will
the subclass implicitly be
will call inserted as
super() when the first
Select the correct statement: run statement. 0 1 0
What is the output :
interface A{
void method1();
void method2();
}
class Test implements A{
public void method1(){
System.out.println("hello");}}
Inheritance_I class RunTest{
nterfaces_Ab public static void main(String[] args){
stract Test obj = new Test();
Classes_New obj.method1();
QB }} hello compile error runtime error none 0 1 0

Given the following classes and declarations,

which statements are true?


// Classes
class Foo {
private int i;
public void f() { /* ... */ }
public void g() { /* ... */ }
}
class Bar extends Foo {
public int j;
Inheritance_I public void g() { /* ... */ }
nterfaces_Ab }
stract // Declarations: The Bar class The The The

QB Bar b = new Bar(); of Foo. = 5; is legal. f(); is legal. g(); is legal. 0.333333 0 0.333333 0.333333
Inheritance_I
nterfaces_Ab Given a derived class method which overrides by creating cannot call
stract one of it’s base class methods. With derived an instance because it is
Classes_New class object you can invoke the overridden super of the base overridden in
QB base method using: keyword this keyword class derived class 1 0 0 0
Consider the following code and choose the

correct option:
abstract class Car{
abstract void accelerate();
}class Lamborghini extends Car{
@Override
void accelerate() {
System.out.println("90 mph");
Inheritance_I } void nitroBooster(){
nterfaces_Ab System.out.print("150 mph"); }
stract public static void main(String[] args) { Compiles but
Classes_New Car mycar=new Lamborghini(); Compilation error at run
QB mycar.nitroBooster(); }} error time 90 mph 150 mph 1 0 0 0

Inheritance_I nterfaces_Ab Given: A NullPointerEx ception is thrown


stract Classes_New QB class Pizza {
java.util.ArrayList toppings;
public final void addTopping(String topping) {
toppings.add(topping);
}
}
public class PepperoniPizza extends Pizza { public void addTopping(String
topping) { System.out.println("Cannot add Toppings");
}
public static void main(String[] args) { Pizza pizza = new PepperoniPizza();
pizza.addTopping("Mushrooms");
}
}
What is the result?

Inheritance_I nterfaces_Ab Consider the following code and choose the


stract Classes_New QB correct option: interface console{ int line=10;
Inheritance_I nterfaces_Ab void print();}
stract Classes_New QB class a implements console{ void print(){ System.out.print("A");}
public static void main(String ar[]){
new a().print();}}

Inheritance_I nterfaces_Ab stract Classes_New QB No—there No—but a object can be assigned to any reference variable.
must always be an exact match between the object of parent type
variable and can be
Inheritance_I nterfaces_Ab stract Classes_New QB No—there object can be assigned to any reference variable.
must always be an exact match between the
variable and

subclass and super() nor its superclass this() is Calling


super() as the first statement in

do not have declared as the body of a


A super() or any declared the first If super() is constructor of
this() call constructors, statement in the first a subclass
must always the implicit the body of a statement in will always
be provided the body of a work, since
Inheritance_I explicitly as constructor, all
nterfaces_Ab stract Classes_New QB the first statement in the body of a constructor. this() can be declared as superclasses have a
the second statement default constructor.
0

0 0.25

0 0
0

0.333333

0
public final static final final data
data type data type type
Choose the correct declaration of variable in varaibale=inti static data varaiblename variablename
an interface: alization; type variable; ; =intialization; 1 0 0 0

Compiles but
Compilation error at runtime
Fun Time error Fun Run 0 0 1 0

Inheritance_I
nterfaces_Ab stract Classes_New QB
Inheritance_I nterfaces_Ab Consider the following code and choose the
stract Classes_New QB correct option: abstract class Fun{ void time(){
System.out.println("Fun Time"); }}
class Run extends Fun{ void time(){ System.out.println("Fun Run"); }
public static void main(String[] args) { Fun f1=new Run();
f1.time(); }}

interface Vehicle{

void drive();
}
final class TwoWheeler implements Vehicle{
int wheels = 2;
public void drive(){
System.out.println("Bicycle");
}
}
class ThreeWheeler extends TwoWheeler{
public void drive(){
System.out.println("Auto");
}}
class Test{
public static void main(String[] args){
Inheritance_I ThreeWheeler obj = new ThreeWheeler();
nterfaces_Ab obj.drive();
stract }}
Classes_New consider the code above & select the proper
QB output from the options. Auto Bicycle Auto compile error runtime error 0 0 1
Consider the following code and choose the

correct option:
interface employee{
void saldetails();
void perdetails();
}
abstract class perEmp implements employee{
public void perdetails(){
Inheritance_I System.out.println("per details"); }}
nterfaces_Ab class Programmer extends perEmp{
stract public static void main(String[] args) {
Classes_New perEmp emp=new Programmer(); sal details compilation per details
QB emp.saldetails(); }} sal details per details error sal details 0 0 1 0
Inheritance_I
nterfaces_Ab
stract
Classes_New All data members in an interface are by abstract and public and public ,static default and
QB default final abstract and final abstract 0 0 1 0

Consider the following code and choose the

correct option:
interface console{
int line;
void print();}
Inheritance_I class a implements console{
nterfaces_Ab public void print(){
stract System.out.print("A");} Compiles but
Classes_New public static void main(String ar[]){ Compilation error at run Runs but no
QB new a().print();}} A error time output 0 1 0 0

An abstract

class is one
An abstract which
class is one contains An abstract
Inheritance_I which some defined class is one
nterfaces_Ab contains methods and which
stract general some contains only Abstract
Classes_New Which of the following is correct for an purpose undefined static class can be
QB abstract class. (Choose TWO) methods methods methods declared final 0.5 0.5 0 0

abstract class

Vehicle {
Inheritance_I abstract void
nterfaces_Ab class Vehicle abstract class abstract display(); { abstract class
stract { abstract Vehicle { Vehicle { System.out. Vehicle {
Classes_New Which of the following defines a legal abstract void abstract void abstract void println("Car"); abstract void
QB class? display(); } display(); } display(); } }} display(); } 0 0 0 0
Consider the code below & select the correct

ouput from the options:

class Mountain{

int height;
protected Mountain(int x) { height=x; }
public int getH(){return height;}}

class Alps extends Mountain{


public Alps(int h){ super(h); }
Inheritance_I public Alps(){ this(100); }
nterfaces_Ab public static void main(String[] args) {
stract System.out.println(new Alps().getH()); Compiles but
Classes_New } Compilation error at run Compiles but
QB } 100 error time no output 1 0 0
0 0
0

1 0

1 0

0 0

0 0

0 0 1
0
Consider the given code and select the
correct output:

class SomeException {
}

class A {
public void doSomething() { }
} Compilation Compilation
of class A will of class B will
class B extends A { Compilation fail. fail.
public void doSomething() throws of both Compilation Compilation
SomeException { } classes A & of class B will of class A will
} B will fail succeed succeed 0 0 0 1

through : the
interfaceNam definitions
Is it possible if a class definition implements e. are the same
two interfaces, each of which has the same variableNam it will not
definition for the constant? interface

method can
be a subset of
Inheritance_I Private A subclass the
nterfaces_Ab methods can override parameter list return type as
stract cannot be any method thrown by the of the method the

to a class, Helps
when it does Javadoc to
not find a Helps JVM to build the

0 0.5 0.5 0

String [][]args String args String[] args[] String[] args String args[] 0 0 0 0.5
p@ckage.
Introduction_t subp@ckage. .package.
o_Java_and_ Which of the following options give the valid dollorpack.$p _score.pack. innerp@ckag subpackage.
SDE_NewQB package names? (Choose 3) ack.$$pack $$.$$.$$ pack e innerpackage 0.333333 0.333333 0.333333 0

Object class
Introduction_t Object class cannot be
o_Java_and_ Which of the following statements are true is an abstract instantiated
SDE_NewQB regarding java.lang.Object class? (Choose 2) class directly 0 0 0.5 0.5

Introduction_t Java Java Runtime Database


o_Java_and_ The term 'Java Platform' refers to Compiler Environment Java
SDE_NewQB . (Javac) (JRE) Debugger 0 1 0 0

JDBC_NewQ Which of the following methods are needed registerDriver Class. getConnectio
B for loading a database driver in JDBC? () method forName() n 0 0 1 0
JDBC_NewQ Which of the following methods are needed getConnectio
B for loading a database driver in JDBC? () method forName() n 0 0 1 0
Inheritance_I Compilation of both classes will succeed
nterfaces_Ab stract Classes_New QB

Inheritance_I nterfaces_Ab stract Classes_New QB No—if a No—a class Yes— either of Yes—since
class implements several interfaces, each may not the two
constant must be defined in only one implement variables can
more than be accessed

one interface e matter 0 0 1 0

The
An overriding parameter list
method can of an

declare that it overriding The


throws checked exceptions that are not overriding method must have different

Classes_New overridden in in a method it is that it is overridden


QB Select the correct statement: subclasses superclass overriding overriding method 1 0 0 0

Consider the following code and choose the

correct option:
class A{
void display(){ System.out.println("Hello A");
}}
class B extends A{
void display(){
System.out.println("Hello B"); }}
Inheritance_I public class Test {
nterfaces_Ab public static void main(String[] args) {
stract A a=new B(); Compiles but
Classes_New B b= a; Compilation error at
QB b.display(); }} Hello A error Hello B runtime 0 1 0 0

Helps the

compiler to
find the
source file
that
corresponds
Introduction_t Which of the following option gives one To maintain o_Java_and_
class file find possible
and use Java
of the statement 'the name of the the uniform
while execute the Documentati
SDE_NewQB public class should match with its file name'? standard compiling classes on easily 0 1 0 0

Holds the Holds the

location of Holds the location of


Core Java location of User Defined Holds the
Introduction_t Class Library Java classes, location of
o_Java_and_ Which of the following statement gives the (Bootstrap Extension packages Java
SDE_NewQB use of CLASSPATH? classes) Library and JARs Software 0 0 1 0
Packages can contain Packages can Sub Class and
contain packages Interfaces in the sub packages will be automatically available to
should be

both Classes non-java declared as the outer


Packages and elements private in packages
Introduction_t can contain Interfaces such as order to deny without using
o_Java_and_ Which of the following are true about only Java (Compiled images, xml importing import
SDE_NewQB packages? (Choose 2) Source files Classes) files etc. them statement.
Introduction_t o_Java_and_ Which of the following options give the valid argument
SDE_NewQB types for main() method? (Choose
2)

Object class has the core methods for thread Object class Object class implements Serializable
provides the
method for Set
implementati
on in

synchronizati Collection interface


on framework internally
Java

Connectivity
(JDBC)
registerDriver
() method and Class. forName()
0

0.5

0
0 0

ble to
ResultSetMet DatabaseMet

JDBC_NewQ java.sql. java.sql.


B should we import? Driver Driver DataSource 0 0 1 0
Which of the following method can be used to execute
to execute all type of queries i.e.
JDBC_NewQ executeAllSQ executeQuer executeUpda
B either Selection or Updation SQL Queries? executeAll() L() execute() y() te() 0 0 1 0

JDBC_NewQ Which method will return boolean when we try executeUpda executeSQL( executeQuer
B to execute SQL Query from a JDBC program? te() ) execute() y() 0 0 1 0

Compiles but
JDBC_NewQ will show only Compilation error at run time
B name error will show city 0 0 0 1

JDBC_NewQ It is possible to insert/update record in a table


B by using ResultSet. State TRUE/FALSE true false 1 0
Read only, Updatable,
JDBC_NewQ What is the default type of ResultSet in JDBC Read Only, Updatable, Scroll Scroll
B Forward Only Forward only Sensitive sensitive 1 0 0 0

JDBC_NewQ
B true false 1 0

JDBC_NewQ Both A and B Only A is Only B is Both A and B


B is FALSE TRUE TRUE is TRUE 1 0 0
JDBC_NewQ Only B is Both A and B
B is FALSE TRUE TRUE is TRUE 1 0 0
Using the static method registerDriver

() method
Using which is Either
forName() available in forName() or
JDBC_NewQ which is a DriverManag registerDriver None of the
B how to register driver class in the memory? static method er Class. () given options 0 0

Give Code snipet:


{// Somecode
ResultSet rs = st.executeQuery("SELECT * FROM survey");

while (rs.next()) {
String name = rs.getString("name"); System.out.println(name);

}
rs.close();

// somecode java.sql.
JDBC_NewQ } What should be imported related to java.sql. java.sql. DriverManag java.sql.
B ResultSet? ResultSet Driver er Connection 1 0

Consider the following code & select the


correct option for output.
String sql ="select empno,ename from emp"; PreparedStatement pst=cn. prepareStatement(sql);

System.out.println(pst.toString());
ResultSet rs=pst.executeQuery(); will show first Compiles but
JDBC_NewQ System.out.println(rs.getString(1)+ " "+rs. employee Compilation error at run Compiles but
B getString(2)); record error time no output 0 0

Which of the following methods finds the Connection. aData. aData. Database.

JDBC_NewQ maximum number of connections that a getMaxConn getMaxConn getMaxConn getMaxConn


B specific driver can obtain? ections ections ections ections 0 0
JDBC_NewQ By default all JDBC transactions are
B autocommit. State TRUE/FALSE. true false 1 0
PreparedStat

JDBC_NewQ DriverManag Driver ResultSet Statement ement


B getConnection() is method available in? er Class Interface Interface Interface Interface 1 0
A) By default, all JDBC transactions are auto

commit
B) PreparedStatement suitable for dynamic
sql and requires one time compilation
JDBC_NewQ C) with JDBC it is possible to fetch Only A and B Only B and CBoth A and C
B information about the database is TRUE is True is TRUE All are TRUE 0 0

It returns int
value as mentioned below: > 0 if many columns Contain Null Value < 0 if
It returns true no column

when last contains Null


There is no read column Value = 0 if
such method contain SQL one column
JDBC_NewQ What is the use of wasNull() in ResultSet in ResultSet NULL else contains Null none of the
B interface? interface returns false value listed options 0 1

Given : java.sql. Driver java. sql. DriverManag er


public class MoreEndings {
public static void main(String[] args) throws
Exception {
Class driverClass = Class.forName("sun. jdbc.odbc.JdbcOdbcDriver");
DriverManager.registerDriver((Driver) driverClass.newInstance());
// Some code
} Inorder to compile & execute this code, what java.sql.
Cosider the following code & select the
correct output.
String sql ="select rollno, name from student"; PreparedStatement pst=cn. prepareStatement(sql); System.out.println(pst.toString());
ResultSet rs=pst.executeQuery(); while(rs.next()){ System.out.println(rs.getString(3)); }

applications?
An application can connect to different Databases at the same time. State TRUE/FALSE.
A) It is not possible to execute select query with execute() method
B) CallableStatement can executes store procedures only but not functions
1 0

1 0 0

1 0

0 1

0 0

0
0

1 0

0 0

1 0

1 0

0 0 0

0 1

0 0
JDBC_NewQ Both A and B Both A and B Only A is Only B is
B is FALSE is TRUE TRUE TRUE 0 1 0 0

Consider the code below & select the correct


ouput from the options:

will show all Compiles but Compiles but


JDBC_NewQ row of first Compilation error at run run without
B error time output 0 0 1 0

JDBC_NewQ CallableState PreparedStat


B ment ement RowSet 0 0 1 0

Line 13
creates a
Line 13 directory
Line 16 is An exception creates a File named “c” in
JDBC_NewQ never is thrown at object named the file
B (Choose TWO) executed runtime “c” system. 0 0.5 0.5 0

1) Driver 2)
Connection
ResultSetMet 3) ResultSet
aData 5) 4)
Statement 6) ResultSetMet
DriverManag aData 5)
er 7) Statement 6)

Which one of the following will cause a


compiler error? rod = mos pkt = rat pkt = null rod = rat 0 1 0 0

Consider the code below & select the correct


ouput from the options:
class Test{

A) When one use callablestatement, in that


case only parameters are send over network not sql query.
B) In preparestatement sql query will compile for first time only
String sql ="select * from ?";
String table=" txyz "; PreparedStatement pst=cn. prepareStatement(sql); pst.setString(1,table );
ResultSet rs=pst.executeQuery();
while(rs.next()){
System.out.println(rs.getString(1)); } column
Sylvy wants to develop Student management system, which requires frequent insert operation about student details. In order to insert student record which statement
interface will give good performance Statement

class CreateFile{
public static void main(String[] args) {
try {
File directory = new File("c"); //Line 13
File file = new File(directory,"myFile");
if(!file.exists()) {
file.createNewFile(); //Line 16
}}
catch(IOException e) {
e.printStackTrace }
}}}
If the current direcory does not consists of directory "c", Which statements are true ?

1) Driver 2)
Connection
3) ResultSet
4)

JDBC_NewQ 1) Driver 2) PreparedStat PreparedStat


Connection ement 8) ement 7)
3) ResultSet Callablestate Callablestate
4) ment 9) ment 8)
Which of the following options contains only DriverManag DataBaseMet DataBaseMet All of the
B JDBC interfaces? er 5) Class aData aData given options 0 0 1 0
Consider the code below & select the correct

ouput from the options:

public class Test {

public static void main(String [] args) {


int x = 5;
boolean b1 = true;
boolean b2 = false;
if ((x == 4) && !b2 )
Keywords_va System.out.print("1 ");
riables_opera System.out.print("2 ");
tors_datatype if ((b2 = true) && b1 )
s_NewQB System.out.print("3 "); } 23 13 2 3 1 0 0 0
Keywords_va

riables_opera
tors_datatype Which three are legal array declarations? int [] char [] int [6] Dog myDogs Dog myDogs
s_NewQB (Choose THREE) myScores []; myChars; myScores; []; [7]; 0.333333 0.333333 0 0.333333
Consider the given code and select the

correct output:
class Test{
public static void main(String[] args){
Keywords_va int num1 = 012;
riables_opera int num2 = 0x110; Compiles but
tors_datatype int sum =num1+=num2; error at run Compilation
s_NewQB System.out.println("Ans = "+sum); }} 26 282 time error 0 1 0 0
Say that class Rodent has a child class Rat
and another child class Mouse. Class Mouse has a child class PocketMouse. Examine the following

Keywords_va riables_opera Rodent rod;


tors_datatype s_NewQB Rat rat = new Rat();
Mouse mos = new Mouse(); PocketMouse pkt = new PocketMouse();

public static void main(String[] args) {


parse("Four"); } A
static void parse(String s){ A NumberForm
try { ParseExcepti atException
Keywords_va double d=Double.parseDouble(s); on is thrown is thrown by
riables_opera }catch(NumberFormatException nfe){ by the parse the parse
tors_datatype d=0.0; }finally{ Compilation method at method at
s_NewQB System.out.println(d); } }} error runtime runtime 0 1 0
1 0

1 0

0.5 0

0 0
1 0

0 0

0 0.333333 0

0 0

0
What will be the output of the program?

and the command-line invocation is An exception


is thrown at
> java CommandArgsTwo 1 2 3 012 23 000 runtime 0 0 0 1

Here is the general syntax for method


definition:

return returnValue;
}

same type as method


What is true for the returnType and the the returns to the
returnValue? returnType caller. type 0 0 0 1

Compiles but
Compilation error at run error
time 0 1 0 0

Line 1, Line
3, Line 5 Line 1, Line 5 Line 4 Line 5 0 0 0 0 1

Compiles but Compiles but


Compilation error at run run without
error time output 1 0 0 0

Compiles but
Compilation error at run
4 error time 1 0 0 0
Consider the code below & select the correct
ouput from the options:
class A{
public int a=7;
public void add(){
this.a+=2; System.out.print("a"); }}

public class Test extends A{

public int a=2;


public void add(){
this.a+=2; System.out.print("t"); }
Keywords_va public static void main(String[] args) {
riables_opera A a =new Test();
tors_datatype a.add(); Compilation
s_NewQB System.out.print(a.a); }} t7 t9 a9 error 1 0 0

public class CommandArgsTwo


{
public static void main(String [] argh)
{
int x;
x = argh.length;
for (int y = 1; y <= x; y++)
{

Keywords_va riables_opera System.out.print(" " + argh[y]);


tors_datatype s_NewQB }
}
}

What will be the result of the following

program?
public class Init {
String title;
boolean published;
static int total;
static double maxPrice;
public static void main(String[] args) {
Init initMe = new Init();
double price;
if (true)
price = 100.00; The program The program The program
System.out.println("|" + initMe.title + "|" + will compile, will compile, The program will compile,
Keywords_va initMe.published + "|" + and print and print will compile, and print
riables_opera Init.total + "|" + Init.maxPrice + "|" + price+ "|"); |null|false|0|0. |null|true|0|0. and print | |null|false|0|0.
tors_datatype } 0|0.0|, when 0|100.0|, |false|0|0.0|0. 0|100.0|, Compilation
s_NewQB } run when run 0|, when run when run error 0 0 0

accessModifier returnType methodName( The The returnValue If the The


parameterList ) returnValue can be any type, returnValue must be the same type as the returnType,
{ but will be or be of a type that can
Java statements automatically
converted to

Keywords_va must be returnType returnType is be converted


exactly the when the void then the to returnType
riables_opera returnValue without loss
tors_datatype s_NewQB can be any of
information.

Keywords_va riables_opera Consider the following code and choose the


tors_datatype s_NewQB correct option:
class Test{
class A{ static int x=3; } static void display(){ System.out.println(A.x); }
public static void main(String[] args) {
display(); }} 3

Keywords_va riables_opera Which of the following lines of code will


tors_datatype s_NewQB compile without warning or error?
1) float f=1.3;
2) char c="a";
3) byte b=257;
4) boolean b=null;
5) int i=10; Line 3
Keywords_va riables_opera Consider the following code and choose the
tors_datatype s_NewQB correct option: class Test{ interface Y{
void display(); }
public static void main(String[] args) {
new Y(){
public void display(){ System.out.println("Hello World"); }
}.display(); }} Hello World

Keywords_va riables_opera Consider the following code and choose the


tors_datatype s_NewQB correct option: class Test{ static class A{
interface X{
int z=4; } }
static void display(){ System.out.println(A.X.z); }
public static void main(String[] args) {
display(); }}
1

0 1

0
0

1 0
What will be the output of the program?
What is the output of the following program?

public class MyClass


{
public static void main( String[] args )
{
private static final int value =9;
float total;
Keywords_va total = value + value / 2;
riables_opera System.out.println( total );
tors_datatype } Compilation Runtime
s_NewQB } 13 13.5 13 Error Error 0 0 0
Keywords_va Which of the given options is similar to the
riables_opera following code: value = value sum = sum +
tors_datatype + sum; sum = 1; value = value = value value = value
s_NewQB value += sum++ ; sum + 1; value + sum; + sum; + ++sum; 1 0 0

What will happen if you attempt to compile

and run the following code?


Integer ten=new Integer(10);
Keywords_va Long nine=new Long (9);
riables_opera System.out.println(ten + nine);
tors_datatype int i=1; 19 followed 19 follwed by Compile time 10 followed
s_NewQB System.out.println(i + ten); by 11 20 error by 1 1 0 0
Identify the statements that are correct:
Keywords_va (A) int a = 13, a>>2 = 3
riables_opera (B) int b = -8, b>>1 = -4
tors_datatype (C) int a = 13, a>>>2 = 3 (A), (B), (C) &
s_NewQB (D) int b = -8, b>>>1 = -4 (A), (B) & (C) (D) (C) & (D) (A) & (B) 1 0 0

Consider the following code:

int x, y, z;
y = 1;
Keywords_va z = 5;
riables_opera x = 0 - (++y) + z++;
tors_datatype After execution of this, what will be the values x = -7, y = 1, x = 3, y = 2, z x = 4, y = 1, z x = 4, y = 2, z
s_NewQB of x, y and z? z=5 =6 =5 =6 0 1 0

Here is the general syntax for method

definition:

accessModifier returnType methodName(

parameterList ) It can be
{ omitted, but if
Java statements not omitted
there are The access It can be
return returnValue; several modifier must omitted, but if
Keywords_va } It must choices, agree with not omitted it
riables_opera always be including the type of must be
tors_datatype private or private and the return private or
s_NewQB What is true for the accessModifier? public public value public 0 1 0

public class CommandArgs


{
public static void main(String [] args)
{
String s1 = args[1];
String s2 = args[2]; String s3 = args[3]; String s4 = args[4];
System.out.print(" args[2] = " + s2);
}

}
Keywords_va
riables_opera and the command-line invocation is An exception
tors_datatype is thrown at
s_NewQB > java CommandArgs 1 2 3 4 args[2] = 2 args[2] = 3 args[2] = null runtime 0 0 0
Consider the following code snippet:
Keywords_va int i = 10;
riables_opera int n = ++i%5;
tors_datatype What are the values of i and n after the code
s_NewQB is executed? 10, 1 11, 1 10, 0 11 , 0 0 1 0
Keywords_va
riables_opera
tors_datatype Which will legally declare, construct, and int [] myList = int [] myList = int myList [] [] int myList [] =
s_NewQB initialize an array? {"1", "2", "3"}; (5, 8, 2); = {4,9,7,0}; {4, 3, 7}; 0 0 0

Consider the code below & select the correct

ouput from the options:


public class Test {
public static void main(String[] args) {
int x=5;
Test t=new Test();
t.disp(x);
System.out.println("main X="+x);
Keywords_va }
riables_opera void disp(int x) {
tors_datatype System.out.println("disp X = "+x++); disp X = 6 disp X = 5 disp X = 5 Compilation
s_NewQB }} main X=6 main X=5 main X=6 error 0 1 0
How many objects and reference variables
Keywords_va are created by the following lines of code? Two objects Three objects Four objects Two objects
riables_opera Employee emp1, emp2; and three and two and two and two
tors_datatype emp1 = new Employee() ; reference reference reference reference
s_NewQB Employee emp3 = new Employee() ; variables. variables variables variables. 1 0 0

A) The purpose of the method overriding is to

perform different operation, though input


Keywords_va remains the same.
riables_opera B) one of the important Object Oriented
tors_datatype principle is the code reusability that can be Only A is Only B is Both A and B Both A and B

s_NewQB achieved using abstraction TRUE True is True is FALSE 1 0 0

class Test{

public static void main(String[] args){


byte b=(byte) (45 << 1);
Keywords_va b+=4;
riables_opera System.out.println(b); }} Compiles but
tors_datatype What should be the output for the code written error at run Compilation
s_NewQB above? 48 94 time error 0 1 0
1 0

0
1

0
Keywords_va What is the value of y when the code below is

riables_opera executed?
tors_datatype int a = 4;
s_NewQB int b = (int)Math.ceil(a % 3 + a / 3.0); 1 2 3 4 0 0 1

Consider the following code and choose the

correct option:
class Test{
class A{
interface X{
int z=4; } }
Keywords_va static void display(){
riables_opera System.out.println(new A().X.z); } Compiles but
tors_datatype public static void main(String[] args) { Compilation error at run
s_NewQB display(); }} error time 4 0 1 0

Consider the code below & select the correct

ouput from the options:


public class Test {
public static void main(String[] args) {
Keywords_va String[] elements = { "for", "tea", "too" };
riables_opera String first = (elements.length > 0) ? The variable The variable Compiles but
tors_datatype elements[0] : null; Compilation first is set to first is set to error at
s_NewQB System.out.println(first); }} error null. elements[0]. runtime 0 0 1

Given the following piece of code:

public class Test {


public static void main(String args[]) {
int i = 0, j = 5 ;
for( ; (i < 3) && (j++ < 10) ; i++ ) {
System.out.print(" " + i + " " + j );
}
Keywords_va System.out.print(" " + i + " " + j );
riables_opera }
tors_datatype } 0617283 0617283 0515253 compilation
s_NewQB what will be the output? 8 9 5 fails 1 0 0

Given

class MybitShift
{
public static void main(String [] args)
{
int a = 0x5000000;
System.out.print(a + " and ");
Keywords_va a = a >>> 25;
riables_opera System.out.println(a);
tors_datatype } 83886080 2 and 2 and 83886080
s_NewQB } and -2 83886080 -83886080 and 2 0 0 0

Consider the code below & select the correct

ouput from the options:

public class Test {

int squares = 81;


public static void main(String[] args) {
new Test().go(); }
Keywords_va void go() {
riables_opera incr(++squares);
tors_datatype System.out.println(squares); } Compilation
s_NewQB void incr(int squares) { squares += 10; } } 92 91 error 82 0 0 0

class C{

public static void main (String[] args) {


byte b1=33; //1

b1++; //2
byte b2=55; //3
b2=b1+1; //4
Keywords_va System.out.println(b1+""+b2);

riables_opera }}
tors_datatype Consider the code above & select the correct compile time compile time runtime none of the
s_NewQB output. error at line 2 error at line 4 prints 34,56 exception listed options 0 1 0

What will be the output of the program ?

public class Test

{
public static void main(String [] args)
{
signed int x = 10;
Keywords_va for (int y=0; y<5; y++, x--)
riables_opera System.out.print(x + ", "); An exception
tors_datatype } Compilation is thrown at
s_NewQB } 10, 9, 8, 7, 6, 9, 8, 7, 6, 5, fails runtime 0 0 1

1. public class LineUp {

2. public static void main(String[] args) {


3. double d = 12.345;
4. // insert code here
5. }
6. }
Which code fragment, inserted at line 4,
produces the output | 12.345|?

Keywords_va A. System.out.printf("|%7f| \n", d);

riables_opera B. System.out.printf("|%3.7f| \n", d);


tors_datatype C. System.out.printf("|%7.3d| \n", d);
s_NewQB D. System.out.printf("|%7.3f| \n", d); A B C D 0 0 0

Consider the following code and choose the

correct option:
class Test{
interface Y{
void display(); }
public static void main(String[] args) {
Keywords_va Y y=new Y(){
riables_opera public void display(){ Compiles but Compiles but
tors_datatype System.out.println("Hello World"); } }; Compilation error at run run without
s_NewQB y.display(); }} Hello World error time output 1 0 0
0

1
0 0

0
Simple
Association Dependency Composition 0 0 1 0

How can the doIt() method in A be It is not his.super. ((A) this).


called from an instance method in C? possible super.doIt() doIt() doIt(); A.this.doIt() 1 0 0 0 0

int [] a =
Which of the following will declare an array Array a = {23,22,21,20, int a [] = new
and initialize it with five numbers? new Array(5); 19}; int[5]; int [5] array; 0 1 0 0

Which of the following are correct variable


names? (Choose TWO) int #ss; int 1ah; int _; int $abc; 0 0 0.5 0.5

What is the output of the following:

int a = 0;
int b = 10;

a = --b ;
System.out.println("a: " + a + " b: " + b ); a: 9 b:11 a: 10 b: 9 a: 9 b:9 a: 0 b:9 0 0 1 0

4 random value 1 0 0 0

11, 1 10, 0 11 , 0 0 0 0 1

Consider the following code and choose the


correct output:

value: 0 value: 1 value: 1


count: 1 count: 1 count: 2 0 0 0 1

Compiles but Compiles but


Compilation error at run errorrun without
time output 0 0 0 1

A sequence
} of five 10's Compiles but
} are printed no output 0 0 1 0
Which of the following methods registers a
thread in a thread scheduler? run(); construct(); start(); register(); 0 0 1 0
class Test{

public static void main(String[] args){


int var;
var = var +1;
Keywords_va System.out.println("var ="+var);
riables_opera }} compiles and
tors_datatype consider the code above & select the proper runs with no does not
s_NewQB output from the options. output var = 1 compile run time error 0 0 1
State the class relationship that is being
implemented by the following code:
class Employee
{
private int empid; private String ename; public double getBonus()
{
Accounts acc = new Accounts();
return acc.calculateBonus();
}
}

Keywords_va riables_opera class Accounts


tors_datatype s_NewQB {
public double calculateBonus(){//method's code}
Keywords_va riables_opera } Aggregation
tors_datatype s_NewQB Given classes A, B, and C, where B extends A, and C extends B, and where all classes implement the instance method void doIt().
Keywords_va riables_opera
tors_datatype s_NewQB
Keywords_va riables_opera
tors_datatype s_NewQB

Keywords_va
riables_opera tors_datatype s_NewQB

Keywords_va riables_opera As per the following code fragment, what is


tors_datatype s_NewQB the value of a? String s;
int a;
Keywords_va riables_opera s = "Foolish boy.";
tors_datatype s_NewQB a = s.indexOf("fool"); -1
Consider the following code snippet:
int i = 10;
int n = i++%5;
What are the values of i and n after the code
is executed? 10, 1

Keywords_va riables_opera int value = 0; value: 0


tors_datatype int count = 1;
value = count++ ;
System.out.println("value: "+ value + " count:

s_NewQB " + count); count: 0


Keywords_va riables_opera Consider the following code and select the
tors_datatype s_NewQB correct output: class Test{ interface Y{
void display(); }
public static void main(String[] args) {
new Y(){
public void display(){ System.out.println("Hello World"); } };
}} Hello World

Keywords_va riables_opera What is the output of the following program? A sequence of compile time
tors_datatype public class demo { Garbage Values are
public static void main(String[] args) {
int arr[5];
for (int i = 0; i < arr.length; i++) {
arr[i] = arr[i] + 10;
}
for (int j = 0; j < arr.length; j++) System.out.println(arr[j]);

s_NewQB printed Error


Threads_Ne wQB
0

0 0

0.5

0
Runnable target = new MyRunnable(); public class
Thread myThread = new Thread(target); MyRunnable
implements
Which of the following classes can be used to Runnable
Threads_Ne create the target, so that the preceding code {public void compiles
wQB correctly? run(){}} run(){}} {void run(){}} 1 0 0 0

Threads_Ne Which of the following statements can be


wQB used to create a new Thread? (Choose TWO) method. method. method. method method. 0.5 0 0 0.5 0

What will be the output of the program?

Prints "Inside Prints "Inside Throws


Threads_Ne Thread Inside Does not Thread Inside exception at
Threads_Ne class PingPong2 {

synchronized void hit(long n) {


for(int i = 1; i < 3; i++)
System.out.print(n + "-" + i + " ");
}
}
public class Tester implements Runnable {
static PingPong2 pp2 = new PingPong2();
public static void main(String[] args) {
new Thread(new Tester()).start();
new Thread(new Tester()).start();
}
public void run() { pp2.hit(Thread.
currentThread().getId()); } The output The output The output The output
} could be 5-1 could be 6-1 could be 6-1 could be 6-1
wQB Which statement is true? 6-1 6-2 5-2 6-2 5-1 5-2 5-2 6-2 5-1 6-2 5-1 7-1 0 1 0

Consider the following code and choose the

correct option:
class Cthread extends Thread{
public void run(){
System.out.print("Hi");}
public static void main (String args[]){
Cthread th1=new Cthread(); will print Hi
th1.run(); twice and
th1.start(); throws
Threads_Ne th1.run(); Exception at will print Hi Compilation will print Hi
wQB }} run time Thrice error once 0 1 0

class Cthread extends Thread{

public void run(){


System.out.print("Hi");}
public static void main (String args[]){
Cthread th1=new Cthread(); will print Hi
th1.run(); twice and
th1.start(); throws
Threads_Ne th1.start(); will start two will print Hi exception at
wQB }} thread Once will not print runtime 0 0 0

Consider the following code and choose the

correct option:
class Cthread extends Thread{
Cthread(){start();}
public void run(){
System.out.print("Hi");} will create
public static void main (String args[]){ two child
Cthread th1=new Cthread(); threads and will not create
Threads_Ne Cthread th2=new Cthread(); display Hi compilation any child will display Hi
wQB }} twice error thread once 1 0 0
Threads_Ne Which of the following methods are defined in
wQB class Thread? (Choose TWO) start() wait() notify() run() terminate() 0.5 0 0

The following block of code creates a Thread

using a Runnable target:

Extend java. lang.Thread and override the run() public class public class public class Implement java.lang. Thread and implement the start()
MyRunnable MyRunnable MyRunnable
extends implements extends
Runnable Runnable Object{public
{public void void run(){}}
Implement Implement
Extend java. java.lang. java.lang.
lang. Thread and Runnable
Runnable implement the and
and override run() implement the
the start() run()

class MyThread extends Thread


{
MyThread() {}
MyThread(Runnable r) {super(r); }
public void run()
{

System.out.print("Inside Thread ");


}
}

class MyRunnable implements Runnable


{
public void run()
{
System.out.print(" Inside Runnable");
}
}

class Test
{
public static void main(String[] args)
{
new MyThread().start();
new MyThread(new MyRunnable()). start();
}
wQB } Thread" compile Runnable" runtime 1 0 0

A) Multiple processes share same memory

location
B) Switching from one thread to another is
easier than switching from one process to
another
C) Thread makes it possible to maximize
Threads_Ne resource utilization All are Only B and C Only A and B Only C and D
wQB D) Process is a light weight program FALSE is TRUE is TRUE is TRUE 0 1 0
A) Exception is the superclass of all errors
and exceptions in the java language
Threads_Ne B) RuntimeException and its subclasses are Only A is Only B is Both A and B Both A and B
wQB unchecked exception. TRUE TRUE are TRUE are FALSE 0 1 0
0

0.5 0
0

0.5 0

he start()
0

0
What will be the output of the program?

new new Thread


} Runnable new Thread new (new
Threads_Ne which of these will create and start this (MyRunnable (MyRunnable MyRunnable( MyRunnable(
wQB thread? ).start(); ).run(); ).start(); )).start(); 0 0 0 1

Will create
two child
threads and will not create

class MyThread extends Thread


{
public static void main(String [] args)
{
MyThread t = new MyThread();
t.start(); System.out.print("one. "); t.start(); System.out.print("two. ");
}

public void run()


{
System.out.print("Thread "); An exception It prints The output
Threads_Ne } Compilation occurs at "Thread one. cannot be
wQB } fails runtime. Thread two." determined. 0 1 0

Consider the following code and choose the

correct option:
class A implements Runnable{ int k;
public void run(){
k++; } Compiles but
public static void main(String args[]){ throws run
Threads_Ne A a1=new A(); It will start a compilation time a1 is not a
wQB a1.run();} new thread error Exception Thread 0 0 0

Given:

public class Threads4 {


public static void main (String[] args) {
new Threads4().go();
}
public void go() {
Runnable r = new Runnable() {
public void run() {
System.out.print("run");
}
};
Thread t = new Thread(r);
t.start(); The code
t.start(); The code executes
} An exception executes normally, but
Threads_Ne } Compilation is thrown at normally and nothing is
wQB What is the result? fails. runtime. prints "run". printed. 0 1 0

class Thread2 {

public static void main(String[] args) {


new Thread2().go(); }
public void go(){
Runnable rn=new Runnable(){
public void run(){
System.out.println("Good Day.."); } };
Thread t=new Thread(rn); The code
t.start(); executes
}} An exception normally and
Threads_Ne what should be the correct output for the code Compilation is thrown at prints "Good prints Good
wQB written above? fails. runtime. Day.." Day.. Twice 0 0 1

public class MyRunnable implements

Runnable
{
public void run()
{
// some code here
}
Consider the following code and choose the
correct option:
class Nthread extends Thread{ public void run(){ System.out.print("Hi");}
public static void main(String args[]){ Nthread th1=new Nthread();

Threads_Ne Nthread th2=new Nthread(); display Hi compilation any child will display Hi
wQB } twice error thread once 0 0 1

Assume the following method is properly

synchronized and called from a thread A on


an object B:

wait(2000); After the lock

After thread on B is
After calling this method, when will the thread A is notified, released, or Two seconds Two seconds
Threads_Ne A become a candidate to get another turn at or after two after two after thread A after lock B is
wQB the CPU? seconds. seconds. is notified. released. 1 0 0
Threads_Ne wait(), notify() and notifyAll() methods belong Interrupt none of the
wQB to Object class Thread class class listed options 1 0 0
Consider the following code and choose the

correct option:
class Test {
public static void main(String[] args) {
new Test().display("hi", 1);
strings_string new Test().display("hi", "world", 2); }
_buffer_New public void display(String... s, int x) { Compilation
QB System.out.print(s[s.length-x] + " "); } } hi hi hi world world error 0 0 0

Consider the following code and choose the

correct option:
public class Test {
public static void main(String[] args) {
strings_string String name="Anthony Gomes";
_buffer_New int a=111; Compilation
QB System.out.println(name.indexOf(a)); }} 4 2 6 error 1 0 0
1
0

0
1

0
strings_string Given: Compilation fails. 0 0 0 1
_buffer_New String test = "This is a test"; String[] tokens = test.split("\s"); System.out.println(tokens.length);
QB What is the result? 1 4

strings_string Consider the following code and choose the Compilation abc78 error Compiles but 0 0 1 0
_buffer_New correct option: exception at run time
QB public class Test {
public static void main(String[] args) { String data="78";
System.out.println(data.append("abc")); }} 78abc

strings_string Consider the following code and choose the true 1 0 1 0 0


_buffer_New correct option:
QB public class Test {
public static void main(String[] args) { String
name="ALDPR7882E"; System.out.println(name.endsWith("E") &
name.matches("[A-Z]{5}[0-9]{4}[A-Z]"));}} false

strings_string Examine this code: result = stringA. result.concat( result = concat (StringA). concat
concat( stringB. stringA, result+stringA (StringB).
String stringA = "Hello "; String stringB = "
World"; String stringC = " Java"; String result;

_buffer_New Which of the following puts a reference to concat( stringB, +stringB+stri concat
QB "Hello World Java" in result? stringC ) ); stringC ); ngC; (StringC) 1 0 0 0
strings_string For two string objects obj1 and obj2: Only A is Only B is Both A and B Both A and B
_buffer_New A) Use of obj1 == obj2 tests whether two String object
references refer to the same object
B) obj1.equals(obj2) compares the sequence

QB of characters in obj1 and obj2. TRUE TRUE is TRUE is FALSE 0 0 1 0


What is the result of the following:

String ring = "One ring to rule them all,\n"; String find = "One ring to find them.";

if ( ring.startsWith("One") && find.startsWith One ring to One ring to One ring to


("One") )
strings_string System.out.println( ring+find ); rule them all, rule them all, rule them all,
_buffer_New else One ring to One ring to \n One ring to Different
QB System.out.println( "Different Starts" ); find them. find them. find them. Starts 1 0 0 0
Consider the following code and choose the correct option: The code will The program The program The program
class MyClass { String str1="str1"; String str2 ="str2"; String str3="str3"; fail to compile
str1.concat(str2); because the
expression
str3.concat (str1)
will not result in a
valid

strings_string System.out.println(str3.concat(str1)); argument for will print The program will print will print

_buffer_New } the println() str3str1str2, will print str3, str3str1,when str3str2,when

QB } method when run when run run run

Given:
public class Theory {
public static void main(String[] args) { String s1 = "abc";
String s2 = s1;
s1 += "d";
System.out.println(s1 + " " + s2 + " " + (s1==s2));

StringBuffer sb1 = new StringBuffer("abc"); The first line The second The second
StringBuffer sb2 = sb1;
sb1.append("d");
System.out.println(sb1 + " " + sb2 + " " + (sb1==sb2));

strings_string } The first line of output is line of output line of output


_buffer_New } Compilation of output is abcd abc is abcd abc is abcd abcd
QB Which are true? (Choose all that apply.) fails abc abc false false false true
strings_string class StringManipulation{ Cognizant Cognizant Cognizant Technology
_buffer_New public static void main(String[] args){ String str = new Technology
String("Cognizant"); str.concat(" Technology");
StringBuffer sbf = new StringBuffer(" Solutions");
System.out.println(str+sbf);
}}
consider the code above & select the proper

QB output from the options. Solutions Technology Solutions Solutions 0 0 1 0


What does this code write:
strings_string StringTokenizer stuff = new StringTokenizer( abc def ghi abc def + abc def +ghi 0 1 0 0
_buffer_New "abc def+ghi", "+");
QB System.out.println( stuff.nextToken() );
System.out.println( stuff.nextToken() ); abc def
strings_string Consider the following code and choose the Compilation anta error Complies but 1 0 0 0
_buffer_New correct option: exception at run time
QB public class Test {
public static void main(String[] args) { StringBuffer sb = new
StringBuffer ("antarctica");
sb.delete(0,6);
System.out.println(sb); }} tica

strings_string Consider the following code and choose the


_buffer_New correct option:
QB public class Test {
public static void main(String[] args) { String name="vikaramaditya"; System.out.println(name.substring(2, 5).
toUpperCase().charAt(2));}} K A R I 0 0 1 0
0 0 0 1

0 0 1 0

1 0 1 0 0

ngA). concat
ngB).

ncat
1 0 0 0
and B

0 0 1 0

rent
1 0 0 0
am The program

will print

tr1,when str3str2,when

0 0 0 1 0

The second

f output line of output


is abcd abcd
0 0 0.5 0 0.5
nology

0 0 1 0

0 1 0 0
1 0 0 0

0 0 1 0
public void amethod(String s){

String stringB = " Irish"; result = concat


String stringC = " Rose"; stringA. (StringA).
String result; concat( result.concat( concat
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) { StringBuffer sb = new StringBuffer ("antarctica");

sb.reverse();
strings_string sb.replace(2, 7, "c");
_buffer_New sb.delete(0,2);
QB System.out.println(sb); }} acctna iccratna ctna tna 0 0 1

Consider the following code and choose the

correct option:
class Test {
public static void main(String args[]) {
String s1 = "abc";
strings_string String s2 = "def";
_buffer_New String s3 = s1.concat(s2.toUpperCase( ) ); abcabcDE abcdefabc none of the
QB System.out.println(s1+s2+s3); } } abcdefabcdef FDEF DEF listed options 0 0 1

What will be the result when you attempt to


compile and run the following code?. public class Conv
{

public static void main(String argv[]){


Conv c=new Conv();
String s=new String("ello");
c.amethod(s);
}

char c='H';
c+=s; Compilation Compilation Compilation
strings_string System.out.println(c); and output and output and output
_buffer_New } the string the string the string Compile time
QB } "Hello" "ello" elloH error 0 0 0

Consider the following code and choose the

correct option:
public class Test {
public static void main(String[] args) {
strings_string String name="Anthony Gomes";
_buffer_New System.out.println(name.replace('n', name. Compilation
QB charAt(3)).compareTo(name)); }} -6 6 error 1 0 0

Consider the following code and choose the

correct option:
class Test {
public static void main(String args[]) {
String name=new String("batman");
int ibegin=1;
char iend=3;
strings_string System.out.println(name.substring(ibegin,
_buffer_New iend)); Compilation
QB }} bat at atm error 0 1 0

Consider the following code and choose the

correct option:
public class Test {
public static void main(String[] args) {
strings_string StringBuffer sb=new StringBuffer
_buffer_New ("YamunaRiver");
QB System.out.println(sb.capacity()); }} 10 27 24 11 0 1 0

Consider the following code and choose the

correct option:
public class Test {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer
("antarctica");
sb.reverse();
strings_string sb.insert(4, 'r');
_buffer_New sb.replace(2, 4, "c");
QB System.out.println(sb); }} acitcratna acitrcratna accircratna accrcratna 0 0 0
A)A string buffer is a mutable sequence of
strings_string characters.
_buffer_New B) sequece of characters in the string buffer Only A is Only B is Both A and B Both A and B
QB can not be changed. TRUE TRUE is TRUE is FALSE 1 0 0

Examine this code:

String stringA = "Wild"; result =

strings_string stringB. stringA, result+stringA (StringB).


_buffer_New Which of the following puts a reference to concat( stringB, +stringB+stri concat
QB "Wild Irish Rose" in result? stringC ) ); stringC ); ngC; (StringC) 1 0 0

Consider the following code and choose the

correct option:
class Test {
public static void main(String[] args) {
new Test().display(1,"hi");
strings_string new Test().display(2,"hi", "world" ); }
_buffer_New public void display(int x,String... s) { Compilation
QB System.out.print(s[s.length-x] + " "); }} hi hi hi world world error 1 0 0

Consider the following code and choose the

correct option:
public class Test {
public static void main(String[] args) {
strings_string String name="vikaramaditya"; System.out.
_buffer_New println(name.codePointAt(2)+name.charAt Compilation
QB (3)); }} 203 204 205 error 0 1 0

Consider the following code and choose the

correct option:
public class Test {
strings_string public static void main(String[] args) { Compiles but
_buffer_New String data="7882"; exception at Compilation
QB data+=32; System.out.println(data); }} 7914 run time 788232 error 0 0 1
0

0
0

0
EqTest(){

FileOutputStr
eam fos =
the state of
the object s1 Compiles but
IO_Operation will be store Compilation error at run error
s_NewQB }} to file std.txt time 1 0 0 0

Compiles but
IO_Operation error at
s_NewQB System.out.print(ch); } }} console. runtime 0 0 1 0

Compiles but
IO_Operation error at runtime
s_NewQB error value 1 0 0 0
Which code can be inserted at Line X to print
"Equal"?
public class EqTest{
public static void main(String argv[]){ EqTest e=new EqTest();
}

String s="Java";
String s2="java";
// Line X
{
System.out.println("Equal");
}else
{
System.out.println("Not equal");
strings_string } if(s. if(s. if(s.
_buffer_New } if(s.equals equalsIgnore noCaseMatc equalIgnoreC
QB } if(s==s2) (s2)) Case(s2)) h(s2)) ase(s2)) 0 0 1

import java.io.*;

public class MyClass implements Serializable


{
private int a;
public int getA() { return a; }
publicMyClass(int a){this.a=a; }
private void writeObject( ObjectOutputStream
s)
throws IOException {
// insert code here
}
}

Which code fragment, inserted at line 15, will s.

IO_Operation allow Foo objects to be defaultWriteO s.writeObject


s_NewQB correctly serialized and deserialized? s.writeInt(x); s.serialize(x); bject(); (x); 0 0 1

FileOutputStr FileOutputStr DataOutputSt new


eam fos = eam fos = ream dos = FileOutputStr
new new new eam( new
FileOutputStr FileOutputStr DataOutputSt BufferedOutp
Which of the following opens the file "myData. eam( eam( ream( utStream(
IO_Operation stuff" for output first deleting any file with that "myData. "myData. "myData. "myData.
s_NewQB name? stuff", true ) stuff") stuff" ) stuff") ) 0 1 0

import java.io.*;

public class MyClass implements Serializable


{

private Tree tree = new Tree();

public static void main(String [] args) {

MyClass mc= new MyClass();


try {
FileOutputStream fs = new FileOutputStream
(”MyClass.ser”); A instance of
ObjectOutputStream os = new MyClass and
ObjectOutputStream(fs); an instance
os.writeObject(mc); os.close(); An exception An instance of Tree are
IO_Operation } catch (Exception ex) { ex.printStackTrace(); } Compilation is thrown at of MyClass is both
s_NewQB }} fails runtime serialized serialized 1 0 0

Consider the following code and choose the the state of the object s1 will not be store to the
correct option: file.
class std implements Serializable{
int call; std(int c){call=c;}
int getCall(){return call;}
}
public class Test{
public static void main(String[] args) throws
IOException {
File file=new File("d:/std.txt"); FileOutputStream fos=new FileOutputStream(file); ObjectOutputStream
oos=new ObjectOutputStream(fos);
std s1=new std(10); oos.writeObject(s1); oos.close();

Consider the following code and choose the reads data Compilation reads data from file named jlist.lst in byte form and ascii
correct option: from file one
public class Test { byte at a time
public static void main(String[] args) throws and display it
IOException { on the
File file=new File("D:/jlist.lst");
byte buffer[]=new byte[(int)file.length()+1]; FileInputStream fis=new FileInputStream
(file);
int ch=0;
while((ch=fis.read())!=-1){

error value
Consider the following code and choose the reads data Compilation reads data from file named jlist.lst in byte form and display garbage
correct option: from file one
public class Test { byte at a time
public static void main(String[] args) throws and display it
IOException { on the console.
File file=new File("D:/jlist.lst");
byte buffer[]=new byte[(int)file.length()+1]; FileInputStream fis=new FileInputStream
(file);
int ch=0; while((ch=fis.read())!=-1){ System.out.print((char)ch); } }}
0

0 0

0
0
the state of
the object s1 Compiles but
IO_Operation will be store Compilation error at run time
s_NewQB }} to file std.txt error 0 0 1 0

Compiles but
IO_Operation error at runtime
s_NewQB } on console. error 0 1 0 0

Compiles but
IO_Operation error at runtime
s_NewQB 1 0 0 0

What happens when the constructor for throws a throws a


IO_Operation FileInputStream fails to open a file for DataFormatE FileNotFound utOfBoundsE
s_NewQB reading? xception Exception xception returns null 0 1 0 0

Compiles but
IO_Operation Compilation error at run time
s_NewQB error 0 0 0 1
Consider the following code and choose the

correct option:
public class Test { Compiles and
public static void main(String[] args) { creates Compiles but executes but
IO_Operation File file=new File("d:/prj/lib"); directory d: Compilation error at run directory is
s_NewQB file.mkdirs();}} /prj/lib error time not created 1 0 0 0
Consider the following code and choose the

correct option:
public class Test {
public static void main(String[] args) throws
IOException {
String data="Confidential info";
byte buffer[]=data.getBytes();
FileOutputStream fos=new writes data to
FileOutputStream("d:/temp"); writes data to the file in Compiles but
IO_Operation for(byte d : buffer){ file in byte Compilation character error at
s_NewQB fos.write(d); } }} form. error form. runtime 1 0 0 0
Given : Compilation

import java.io.*;
public class ReadingFor {
public static void main(String[] args) {
String s;
try {
FileReader fr = new FileReader("myfile.txt");
BufferedReader br = new BufferedReader(fr);
while((s = br.readLine()) != null)
System.out.println(s);
br.flush();
} catch (IOException e) { System.out.println
("io error"); }
}
}
And given that myfile.txt contains the following
two lines of data:
ab
IO_Operation cd
s_NewQB What is the result? ab abcd ab cd abcd Error 0 0 0
Consider the following code and choose the the state of the object s1 will not be store to the file.
correct option:
class std{
int call; std(int c){call=c;}
int getCall(){return call;}
}
public class Test{
public static void main(String[] args) throws
IOException {
File file=new File("d:/std.txt"); FileOutputStream fos=new FileOutputStream(file); ObjectOutputStream oos=new
ObjectOutputStream(fos);
std s1=new std(10); oos.writeObject(s1); oos.close();

Consider the following code and choose the reads data from file named reads data from file named jlist.lst in byte form and display garbage
correct option: jlist.lst in byte form value
public class Test { and display it Compilation
public static void main(String[] args) { File file=new File("D:/jlist.lst");
byte buffer[]=new byte[(int)file.length()+1]; FileInputStream fis=new FileInputStream
(file);
fis.read(buffer); System.out.println(buffer);
}

Consider the following code and choose the reads data from file named reads data from file named jlist.lst in byte form and display garbage
correct option: jlist.lst in byte form
public class Test { and display it Compilation
public static void main(String[] args) throws
IOException {
File file=new File("D:/jlist.lst");
byte buffer[]=new byte[(int)file.length()+1]; FileInputStream fis=new FileInputStream
(file);
fis.read(buffer);

System.out.println(new String(buffer)); }} on console. error value


throws a
ArrayIndexO

Consider the following code and choose the creates directories names prj Compiles and executes but directories
correct option: and lib in d: drive are not created
public class Test {
public static void main(String[] args) { File file=new File("d:/prj,d:/lib"); file.mkdirs();}}
1 0

0 0

0 0

0 0

0 0
0 0

0 1
Consider the following code and choose the
correct output:
public class Person{
public void talk(){ System.out.print("I am a
Person "); }
}
public class Student extends Person {
public void talk(){ System.out.print("I am a
Student "); }
}
what is the result of this piece of code:
public class Test{
public static void main(String args[]){
Person p = new Student();
p.talk(); I am a I am a
IO_Operation } I am a I am a Person I am Student I am
s_NewQB } Person Student a Student a Person 0 1 0 0
Which of these are two legal ways of

accessing a File named "file.tst" for reading.


Select the correct option:
A)FileReader fr = new FileReader("file.tst");
B)FileInputStream fr = new FileInputStream
("file.tst");
C)InputStreamReader isr = new
InputStreamReader(fr, "UTF8");
IO_Operation D)FileReader fr = new FileReader("file.tst",
s_NewQB "UTF8"); A,D B,C C,D A,B 0 0 0 1
What is the DataOutputStream method that
IO_Operation writes double precision floating point values to
s_NewQB a stream? writeBytes() writeFloat() write() writeDouble() 0 0 0 1

Consider the following code and choose the

correct option:
public class Test{
public static void main(String[] args) {
File dir = new File("dir"); The file
dir.mkdir(); The file The file system has a
File f1 = new File(dir, "f1.txt"); try { The file system has a system has a directory
f1.createNewFile(); } catch (IOException e) { system has a new empty directory named
;} new empty directory named dir, newDir,
IO_Operation File newDir = new File("newDir"); directory named containing a containing a Compilation
s_NewQB dir.renameTo(newDir);} } named dir newDir file f1.txt file f1.txt error 0 0 0 1
Consider the following code and choose
the correct option:
public class Test {
public static void main(String[] args)
throws IOException {
File file=new File("d:/data");
byte buffer[]=new byte[(int)file.length()
+1];
FileInputStream fis=new FileInputStream
(file); Compiles and
fis.read(buffer); Transfer runs but
FileWriter fw=new FileWriter("d:/temp. content of file Compiles but content not
IO_Operation txt"); data to the Compilation error at transferred to
s_NewQB fw.write(new String(buffer));}} temp.txt error runtime the temp.txt 0 0 0 1
import java.io.EOFException;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class MoreEndings {
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream
("seq.txt");
InputStreamReader isr = new
InputStreamReader(fis);
int i = isr.read();
while (i != -1) {
System.out.print((char)i + "|");
i = isr.read();
}
} catch (FileNotFoundException fnf) {
System.out.println("File not found");
} catch (EOFException eofe) {
System.out.println("End of stream");
} catch (IOException ioe) {
System.out.println("Input error");
} The program
} will not
} compile The program
Assume that the file "seq.txt" exists in the because a The program The program will compile,
current directory, has the required certain will compile will compile print H|e|l|l|o|,
access permissions, and contains the string unchecked and print and print and then
IO_Operation "Hello". exception is H|e|l|l|o|Input H|e|l|l|o|End terminate
s_NewQB Which statement about the program is true? not caught. error. of stream. normally. 0 0 0 1
Consider the following code and choose the

correct option:
public class Test{ Skip the first
public static void main(String[] args) throws seven
IOException { characters
File file = new File("d:/temp.txt"); and then
FileReader reader=new FileReader(file); starts reading
reader.skip(7); int ch; file and Compiles and Compiles but
IO_Operation while((ch=reader.read())!=-1){ display it on Compilation runs without error at
s_NewQB System.out.print((char)ch); } }} console error output runtime 1 0 0 0

The file is

modified from
A file is readable but not writable on the file A being
system of the host platform. What will SecurityExce The boolean The boolean unwritable to
IO_Operation be the result of calling the method canWrite() ption is value false is value true is being none of the
s_NewQB on a File object representing this file? thrown returned returned writable. listed options 0 1 0
0

1 0

0 1
0 0

0 0
Introduction_t void add(int void add(int void add(int
x,int y) char char add(float x,int y) char x,int y) void

o_OOPS_Ne Which of following set of functions are add(int x,int x) char add add(char x, sum(double

wQB example of method overloading y) (float y) char y) x,double y) 0 0 1 0


Efficient avoiding

Introduction_t What is the advantage of runtime utilization of Code method name


o_OOPS_Ne memory at flexibility at confusion at
wQB polymorphism? runtime Code reuse runtime runtime 0 0 1 0
Introduction_t Which of the following is an example of IS A Microprocess
o_OOPS_Ne or -
wQB relationship? Ford - Car Computer Tea -Cup Driver -Car
Introduction_t

o_OOPS_Ne Which of the following is not a valid relation Segmentatio


wQB between classes? Inheritance n Instantiation Composition
Introduction_t

o_OOPS_Ne Which of the following is not an attribute of


wQB object? State Behaviour Inheritance Identity 0 0 0 1
(int
oid

uble

) 0 0 1 0

me
at
0 0 1 0

1 0 0 0

0 1 0 0

0 0 0 1