[go: up one dir, main page]

0% found this document useful (0 votes)
186 views65 pages

Core Java-Mcqs

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 65

QuestionText QuestionType Choice1 Choice2 Choice3 Choice4 Choice5 Grade1 Grade2 Grade3 Grade4 Grade5

Consider the following code and choose the MCQ Compiles and Compiles and Compiles and Compilation 0 0
correct option: display 2 runs without display 0 error
class X { int x; X(int x){x=2;}} any output
class Y extends X{ Y(){} void displayX(){
System.out.print(x);}
public static void main(String args[]){
new Y().displayX();}} 0 1
Consider the following code and choose the MCQ Compiles and Compiles and Compiles but Compilation 0 0
correct option: prints show() prints throws error
class Test{ private void display(){ Display() runtime
System.out.println("Display()");} show() exception
private static void show() { display();
System.out.println("show()");}
public static void main(String arg[]){
show();}} 0 1
Consider the following code and choose the MCQ Compilation Comiples and Compiles but Compiles and 0 1
correct option: error prints From A throws display 3
class A{ A(){System.out.print("From A");}} runtime
class B extends A{ B(int z){z=2;} exception
public static void main(String args[]){
new B(3);}} 0 0
class One{ MCQ 0,0 compiles compile error none of these 0 0
int var1; successfully
One (int x){ but runtime
var1 = x; error
}}
class Derived extends One{
int var2;
void display(){
System.out.println("var
1="+var1+"var2="+var2);
}}
class Main{
public static void main(String[] args){
Derived obj = new Derived();
obj.display();
}}
consider the code above & select the proper
output from the options. 1 0
Consider the following code and choose the MCQ code compiles code compiles j can not be compliation 0 0
correct option: fine and will but will not initialized error
package aj; class A{ protected int j; } display 23 display output
package bj; class B extends A
{ public static void main(String ar[]){
System.out.print(new A().j=23);}} 0 1
class Order{ MCQ compile error Man Dog Cat Dog Man Cat Cat Ant Dog 0 0
Order(){ Ant Ant Man
System.out.println("Cat");
}
public static void main(String... Args){
Order obj = new Order();
System.out.println("Ant");
}
static{
System.out.println("Dog");
}
{
System.out.println("Man");
}}
consider the code above & select the proper
output from the options. 1 0
public class MyAr { MCQ Unresolved Compilation None of the 0 1
public static void main(String argv[]) { compilation and output of given options
MyAr m = new MyAr(); problem: The null
m.amethod(); local variable
} i1 may not
public void amethod() { have been
final int i1; initialized
System.out.println(i1);
}
}
What is the Output of the Program? 0 0
class MyClass1 MCQ Compilation Runtime 2500 50 0 0
{ error Exception
private int area(int side)
{
return(side * side);
}
public static void main(String args[ ])
{
MyClass1 MC = new MyClass1( );
int area = MC.area(50);
System.out.println(area);
}
}
What would be the output? 1 0
class Sample MCQ 100 100 1 2 1 2 100 100 10 20 1 2 100 1 2 10 20 100 0 0
{int a,b; 10 20 10 20 100 100
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[])
{
Sample s1=new Sample (100);
}
}
What is the Output of the Program? 0 1
Consider the following code and choose the MCQ prints Hi Hello Compiler Runs but no Runtime Error 0 1
correct option: Error output
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]);
}
}
Command Line arguments - Hi, Hello 0 0
Given: MCQ int Long Short Long Compilation An exception 1 0
public class Yikes { fails. is thrown at
runtime.
public static void go(Long n)
{System.out.print("Long ");}
public static void go(Short n)
{System.out.print("Short ");}
public static void go(int n)
{System.out.print("int ");}
public static void main(String [] args) {
short y = 6;
long z = 7;
go(y);
go(z);
}
}
What is the result? 0 0
abstract class MineBase { MCQ A Sequence A Sequence IndexOutOfBo Compilation 0 0
abstract void amethod(); of 5 zero's will of 5 one's will undes Error Error occurs
static int i; be printed like be printed like and to avoid
} 00000 11111 them we need
public class Mine extends MineBase { to declare
public static void main(String argv[]){ Mine class as
int[] ar=new int[5]; abstract
for(i=0;i < ar.length;i++)
System.out.println(ar[i]);
}
} 0 1
What will be the result when you attempt to MCQ Compile time A random A random A compile 1 0
compile this program? error referring number number time error as
public class Rand{ to a cast between 1 between 0 random being
public static void main(String argv[]){ problem and 10 and 1 an undefined
int iRand; method
iRand = Math.random();
System.out.println(iRand);
}
} 0 0
Which of the following declarations are MCA boolean b = byte b = 256; String s = int i = new 0 0
correct? (Choose TWO) TRUE; “null”; Integer(“56”); 0.5 0.5
class A, B and C are in multilevel inheritance MCQ Constructor of Constructor of Constructor of Constructor of 1 0
hierarchy repectively . In the main method of A executes C executes C executes A executes
some other class if class C object is created, in first, followed first followed first followed first followed
what sequence the three constructors execute? 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 0 0
What will be the result when you try to compile MCQ 200 100 followed Compile time 100 0 0
and run the following code? by 200 error
private class Base{
Base(){
int i = 100;
System.out.println(i);
}
}

public class Pri extends Base{


static int i = 200;
public static void main(String argv[]){
Pri p = new Pri();
System.out.println(i);
}
} 1 0
Suppose class B is sub class of class A: MCQ Only B and C Only A is All are FALSE Only A and C 1 0
A) If class A doesn't have any constructor, then is TRUE TRUE is TRUE
class B also must not have any constructor
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
0 0
What will be printed out if you attempt to MCQ default zero default zero Compilation default 0 1
compile and run the following code ? one two Error
public class AA {
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");
case 2:
System.out.println("two");
}
}
} 0 0
Consider the following code and choose the MCQ Compiles but Compiles and Compilation Compiles and 0 0
correct option: no output diplay 0 error display 1
package aj; private class S{ int roll;
S(){roll=1;} }
package aj; class T
{ public static void main(String ar[]){
System.out.print(new S().roll);}} 1 0
public class Q { MCQ Compiler 2 1 Compiler 0 1
public static void main(String argv[]) { Error: anar is Error: size of
int anar[] = new int[] { 1, 2, 3 }; referenced array must be
System.out.println(anar[1]); before it is defined
} initialized
} 0 0
Which statements, when inserted at (1), will not MCA i= i = this.suns; this = new this.i = 4; this.suns = 0.33 0.33
result in compile-time errors? this.planets; ThisUsage(); planets;
public class ThisUsage {
int planets;
static int suns;
public void gaze() {
int i;
// (1) INSERT STATEMENT HERE
}
} 0 0 0.33
Given the following code what will be output? MCQ Error: 10 and 40 10, and 20 20 and 40 0 1
public class Pass{ amethod
static int j=20; parameter
public static void main(String argv[]){ does not
int i=10; match
Pass p = new Pass(); variable
p.amethod(i);
System.out.println(i);
System.out.println(j);
}

public void amethod(int x){


x=x*2;
j=j*2;
}
} 0 0
class Order{ MCQ Dog Ant Dog Man Cat Man Dog Ant Dog Man Ant 1 0
Order(){ Ant
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
output from the options. 0 0
public class c123 { MCQ Hellow It is not Compilation Runs without 0 0
private c123() { possible to Error any output
System.out.println("Hellow"); declare a
} constructor as
public static void main(String args[]) { private
c123 o1 = new c123();
c213 o2 = new c213();
}
}
class c213 {
private c213() {
System.out.println("Hello123");
}
}

What is the output? 1 0


class A { MCQ This is j: 5 i This is i: 3 j This is i: 7 j This is k: 7 i 0 0
int i, j; and k: 3 7 and k: 5 7 and k: 3 5 and j: 3 7

A(int a, int b) {
i = a;
j = b;
}
void show() {
System.out.println("i and j: " + i + " " + j);
}
}
class B extends A {
int k;

B(int a, int b, int c) {


super(a, b);
k = c;
}
void show(String msg) {
System.out.println(msg + k);
}
}
class Override {
public static void main(String args[]) {
B subOb = new B(3, 5, 7);
subOb.show("This is k: "); // this calls show()
in B
subOb.show(); // this calls show() in A
}
} What would be the ouput? 0 1
public class MyAr { MCQ Compilation Garbage It is not 1 0
static int i1; Error Value possible to
public static void main(String argv[]) { access a
MyAr m = new MyAr(); static variable
m.amethod(); in side of non
} static method
public void amethod() {
System.out.println(i1);
}
}
What is the output of the program? 0 0
Given: MCQ Meal() Meal() Meal() Cheese() 1 0
package QB; Lunch() Cheese() Lunch() Sandwich()
PortableLunch Lunch() PortableLunch Meal()
class Meal { () Cheese() PortableLunch () Sandwich() Lunch()
Meal() { Sandwich() () Sandwich() Cheese() PortableLunch
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();

public Sandwich() {
System.out.println("Sandwich()");
}
}
public class MyClass7 {
public static void main(String[] args) { 0 0
new Sandwich();
Consider the following code and choose the MCQ compiles and compilation Compiles and Compiles and 1 0
correct option: display 0 error display 4 display 3
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();}} 0 0
class Order{ MCQ Cat Ant Dog Dog Cat Ant Ant Cat Dog none 0 1
Order(){
System.out.println("Cat");
}
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. 0 0
What will happen if a main() method of a MCQ The compiler The compiler The program The program 0 1
"testing" class tries to access a private instance will will find the will compile will compile
variable of an object using dot notation? automatically error and will and run successfully,
change the not make a successfully but the .class
private .class file file will not run
variable to a correctly
public variable
0 0
What will be the result of compiling the MCQ The program A compilation A compilation A compilation 1 0
following program? will compile error will error will error will
public class MyClass { without errors. occur at (Line occur at (Line occur at (2),
long var; no 2), since no 1), since since the
public void MyClass(long param) { var = the class does constructors class does not
param; } // (Line no 1) not have a cannot specify have a default
public static void main(String[] args) { constructor a return value constructor
MyClass a, b; that takes one
a = new MyClass(); // (Line no 2) argument of
} type int.
} 0 0
public class MyClass { MCQ String: String int: 27, String: Compilation Runtime 1 0
static void print(String s, int i) { first, int: 11 Int first String: Error Exception
System.out.println("String: " + s + ", int: " + i); int: 99, String: String first, int:
} Int first 27

static void print(int i, String s) {


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

public static void main(String[] args) {


print("String first", 11);
print(99, "Int first");
}
}What would be the output?

0 0
Here is the general syntax for method MCQ The If the The The 0 0
definition: returnValue returnType is returnValue returnValue
can be any void then the must be the must be
accessModifier returnType methodName( type, but will returnValue same type as exactly the
parameterList ) be can be any the same type as
{ automatically type returnType, or the
Java statements converted to be of a type returnType.
returnType that can be
return returnValue; when the converted to
} method returnType
returns to the without loss of
caller information
What is true for the returnType and the
returnValue? 1 0
11. class Mud { MCQ 3 1 2 1 0
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) {
public static void main(String... a) {
public static void main(String[]... a) {
public static void main(String...[] a) {
How many of the code fragments, inserted
independently at line 12, compile? 0 0
package QB; MCQ methodRadius sp.methodRa Nothing to add Sphere.metho 0 1
class Sphere { (x); dius(x); dRadius();
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;
Sphere sp = new Sphere();
// Some code missing
}
} to get the radius value what is the code of line
to be added ? 0 0
A) A call to instance method can not be made MCQ Only B is Only A is Both are Both are 0 0
from static context. TRUE TRUE TRUE FALSE
B) A call to static method can be made from
non static context. 1 0
Consider the following code and choose the MCQ Compiles and Compiles and Compilation Compiles but 0 0
correct option: displays Hi throws run fails doesn't
class A{ private void display(){ time exception display
System.out.print("Hi");} anything
public static void main(String ar[]){
display();}} 1 0
class One{ MCQ var1=10 , 0,0 compile error runtime error 1 0
int var1; var2=10
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){
Derived obj = new Derived();
obj.display();
}}
consider the code above & select the proper
output from the options. 0 0
public class MyAr { MCQ Compile time Compilation It is not 0 0
public static void main(String argv[]) { error because and output of possible to
MyAr m = new MyAr(); i has not been null declare a
m.amethod(); initialized static variable
} in side of non
public void amethod() { static method
static int i1; or instance
System.out.println(i1); method.
} Because
} Static
What is the Output of the Program? variables are
class level
dependencies.
0 1
Consider the following code and choose the MCQ Compilation Compiles but Compiles and None of the 1 0
correct option: error throws run displays listed options
class A{ int z; A(int x){z=x;} } time exception nothing
class B extends A{
public static void main(String arg){
new B();}} 0 0
A) No argument constructor is provided to all MCQ Only A is All are TRUE B and C is All are FALSE 0 0
Java classes by default TRUE TRUE
B) No argument constructor is provided to the
class only when no constructor is defined.
C) Constructor can have another class object
as an argument
D) Access specifiers are not applicable to
Constructor
1 0
Which modifier is used to control access to MCQ default public transient synchronized 0 0
critical code in multi-threaded programs? 0 1
public class c1 { MCQ Hello It is not Compilation Can't create 1 0
private c1() possible to Error object
{ declare a because
System.out.println("Hello"); constructor constructor is
} private private
public static void main(String args[])
{
c1 o1=new c1();
}
}

What is the output? 0 0


Which of the following sentences is true? MCQ Only A and C All are TRUE All are FALSE Only A is 0 0
A) Access to data member depends on the is TRUE TRUE
scope of the class and the scope of data
members
B) Access to data member depends only on the
scope of the data members
C) Access to data member depends on the
scope of the method from where it is accessed
0 1
Consider the following code and choose the MCQ Compiles and Compiles and Compiles but Compilation 0 1
correct option: prints show() prints throws error
class Test{ private static void display(){ Display() runtime
System.out.println("Display()");} show() exception
private static void show() { display();
System.out.println("show()");}
public static void main(String arg[]){
show();}} 0 0
Consider the following code and choose the MCQ Compiles and Compiles and Compiles but Compilation 1 0
correct option: display Hi throw run time doesn't fails
class A{ private static void display(){ exception display
System.out.print("Hi");} anything
public static void main(String ar[]){
display();}} 0 0
Which of the following will print -4.0 MCQ System.out.pri System.out.pri System.out.pri System.out.pri 1 0
ntln(Math.ceil(- ntln(Math.floor ntln(Math.roun ntln(Math.min(-
4.7)); (-4.7)); d(-4.7)); 4.7)); 0 0
class Test{ MCQ hello Runtime Error compiles but does not 0 0
static void method(){ no output compile
this.display();
}
static display(){
System.out.println(("hello");
}
public static void main(String[] args){
new Test().method();
}
}
consider the code above & select the proper
output from the options. 0 1
Consider the following code and choose the MCQ Compilation Compiles and Compiles and Compiles and 0 0
best option: error display 0 display 2 runs without
class Super{ int x; Super(){x=2;}} any output
class Sub extends Super { void displayX(){
System.out.print(x);}
public static void main(String args[]){
new Sub().displayX();}} 1 0
Which modifier indicates that the variable MCQ synchronized volatile transient default 0 1
might be modified asynchronously, so that all
threads will get the correct value of the
variable. 0 0
A constructor may return value including class MCQ true false 0 1
type
Consider the following code and choose the MCQ Compilation Compiles and Compiles and Compiles but 1 0
correct option: error display 0 display 23 no output
package aj; class S{ int roll =23;
private S(){} }
package aj; class T
{ public static void main(String ar[]){
System.out.print(new S().roll);}} 0 0
What will happen when you attempt to compile MCQ The code will The compiler The code will The compiler 1 0
and run this code? compile and will complain compile but will complain
abstract class Base{ run, printing that the Base complain at that the
abstract public void myfunc(); out the words class has non run time that method
public void another(){ "My Func" abstract the Base class myfunc in the
System.out.println("Another method"); methods has non base class
} abstract has no body,
} methods nobody at all
to print it
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My Func");
}
public void amethod(){
myfunc();
}
} 0 0
Given: MCQ Compilation Cannot add The code runs A 1 0
class Pizza { fails. Toppings with no NullPointerEx
java.util.ArrayList toppings; output. ception is
public final void addTopping(String topping) { thrown
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?
0 0
When we use both implements & extends MCQ we must use we must use we can use in extends and 1 0
keywords in a single java program then what is always always any order its implements
the order of keywords to follow? extends and implements not at all a can't be used
later we must and later we problem together
use must use
implements extends
keyword. keyword. 0 0
Consider the following code and choose the MCQ sal details sal details per compilation per details sal 0 0
correct option: details error details
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(); }}
0 1
Consider the following code and choose the MCQ 3 4 compilation Compiles but 0 0
correct option: error error at
interface A{ runtime
int i=3;}
interface B{
int i=4;}
class Test implements A,B{
public static void main(String[] args) {
System.out.println(i);
}
} 1 0
Consider the following code: MCQ Illegal at Legal at Definitely Definitely 0 1
// Class declarations: compile time compile time, legal at legal at
class Super {} but might be runtime, but runtime, and
class Sub extends Super {} illegal at the cast the cast
// Reference declarations: runtime operator (Sub) operator (Sub)
Super x; is not strictly is needed.
Sub y; needed.
Which of the following statements is correct for
the code: y = (Sub) x? 0 0
Consider the following code and choose the MCQ Hello A Compilation Hello B Compiles but 0 1
correct option: error error at
class A{ runtime
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= a;
b.display(); }}
0 0
Which of these field declarations are legal in an MCA public static int answer; final static int public int private final 0.25 0
interface? (Choose all applicable) int answer = answer = 42; answer = 42; static int
42; answer = 42; 0.25 0.25 0.25
Consider the following code and choose the MCQ 150 mph Compilation Compiles but 90 mph 0 1
correct option: error error at run
abstract class Car{ time
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();
mycar.nitroBooster(); }} 0 0
Consider the code below & select the correct MCQ A,B,E A,C,D B,D,E C,D,E 0 1
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.)
A. public int height(int x) { return 0; }
B. private int height(int x) { return 0; }
C. private int height(long x) { return 0; }
D. protected long height(long x) { return 0; }
E. protected long height(int x) { return 0; } 0 0
Consider the following code and choose the MCQ sum of byte 7 Compilation sum of int7 Compiles but 0 0
correct option: error error at
class A{ runtime
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
Consider the following code and choose the MCQ A Compilation Compiles but Runs but no 0 1
correct option: error error at run output
interface console{ time
int line;
void print();}
class a implements console{
public void print(){
System.out.print("A");}
public static void main(String ar[]){
new a().print();}} 0 0
Consider the following code and choose the MCQ Hello A Compilation Hello B Compiles but 0 0
correct option: error error at
class A{ runtime
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(); }}
1 0
Which of the following defines a legal abstract MCQ class Vehicle { abstract class abstract abstract class abstract class 0 0
class? abstract void Vehicle { Vehicle { Vehicle { Vehicle {
display(); } abstract void abstract void abstract void abstract void
display(); } display(); } display(); { display(); }
System.out.pri
ntln("Car"); }}

0 0 1
Choose the correct declaration of variable in an MCQ public final static data static final final data type 1 0
interface: data type type variable; data type variablename
varaibale=inti varaiblename; =intialization;
alization; 0 0
Given: MCA p0 = p1; p2 = p4; p1 = p1 = p2; 0.5 0
11. class ClassA {} (ClassB)p3;
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.) 0.5 0
Consider the following code and choose the MCQ Hello A Compilation Hello B Compiles but 0 0
correct option: error error at
class A{ runtime
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) {
B b=(B) new A();
b.display(); }}
0 1
A class Animal has a subclass Mammal. Which MCQ Because of Because of Because of Because of 0 1
of the following is true: single single single single
inheritance, inheritance, inheritance, inheritance,
Mammal can Mammal can Animal can Mammal can
have no have no other have only one have no
subclasses parent than subclass siblings.
Animal 0 0
Given: MCQ s 14 s 16 s 10 Compilation 0 0
interface DeclareStuff { fails.
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);
}
void doStuff(int s) {
s += Easy + ++s;
System.out.println("s " + s);
}
} What is the result? 0 1
Consider the following code and choose the MCQ A Compilation Compiles but Runs but no 0 1
correct option: error error at run output
interface console{ time
int line=10;
void print();}
class a implements console{
void print(){
System.out.print("A");}
public static void main(String ar[]){
new a().print();}} 0 0
Which of the following is correct for an abstract MCA An abstract An abstract An abstract Abstract class 0.5 0.5
class. (Choose TWO) class is one class is one class is one can be
which which which declared final
contains contains some contains only
general defined static methods
purpose methods and
methods some
undefined
methods 0 0
Which declaration can be inserted at (1) MCA int total = total final double protected int int AREA = r * public static 0 0.5
without causing a compilation error? + r + s; circumference CODE = s; MAIN = 15;
interface MyConstants { = 2 * Math.PI * 31337;
int r = 42; r;
int s = 69;
// (1) INSERT CODE HERE
} 0 0.5 0
Given : MCQ No—there No—but a Yes—an Yes—any 0 0
must always object of object can be object can be
Day d; be an exact parent type assigned to a assigned to
BirthDay bd = new BirthDay("Raj", 25); match can be reference any reference
d = bd; // Line X between the assigned to a variable of the variable.
variable and variable of parent type.
Where Birthday is a subclass of Day. State the object child type.
whether the code given at Line X is correct: 1 0
class Animal { MCQ run time error generic noise bark compile error 0 0
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.
1 0
interface Vehicle{ MCQ Auto Bicycle Auto compile error runtime error 0 0
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){
ThreeWheeler obj = new ThreeWheeler();
obj.drive();
}}
consider the code above & select the proper
output from the options. 1 0
Select the correct statement: MCQ Private A subclass An overriding The The overriding 1 0
methods can override method can parameter list method must
cannot be any method in declare that it of an have different
overridden in a superclass throws overriding return type as
subclasses checked method can the overridden
exceptions be a subset of method
that are not the parameter
thrown by the list of the
method it is method that it
overriding is overriding
0 0 0
Consider the code below & select the correct MCQ 3 Compilation Compiles but 9 0 1
ouput from the options: error error at run
class A{ time
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)); }} 0 0
Given: MCQ No—a No—a No—a Yes—the 0 0
public static void main( String[] args ) { variable must variable must variable must variable can
SomeInterface x; ... } always be an always be an always be a refer to any
Can an interface name be used as the type of a object object primitive type object whose
variable reference type reference type class
or a primitive implements
type the interface 0 1
Given : MCQ The code will The code will The code will The code will 0 0
What would be the result of compiling and fail to compile fail to compile compile and compile and
running the following program? because the because a call print 23, when print 29, when
// Filename: MyClass.java max() method to a max() run. run.
public class MyClass { in B passes method is
public static void main(String[] args) { the arguments ambiguous.
C c = new C(); in the call
System.out.println(c.max(13, 29)); super.max(y,
} x) in the
} wrong order.
class A {
int max(int x, int y) { if (x>y) return x; else return
y; }
}
class B extends A{
int max(int x, int y) { return super.max(y, x) -
10; }
}
class C extends B {
int max(int x, int y) { return super.max(x+10,
y+10); }
} 0 1
Given: MCQ Compilation If you define D Compilation If you define D 0 1
interface A { public void methodA(); } fails, due to an e = (D) (new fails, due to an e = (D) (new
interface B { public void methodB(); } error in line 3 E()), then error in line 7 E()), then
interface C extends A,B{ public void e.methodB() e.methodB()
methodC(); } //Line 3 invokes the invokes the
class D implements B { version of version of
public void methodB() { } //Line 5 methodB() methodB()
} defined at line defined at line
class E extends D implements C { //Line 7 9 5
public void methodA() { }
public void methodB() { } //Line 9
public void methodC() { }
}
What would be the result? 0 0
Select the correct statement: MCQ A super() or If both a If neither If super() is Calling 0 1
this() call subclass and super() nor the first super() as the
must always its superclass this() is statement in first statement
be provided do not have declared as the body of a in the body of
explicitly as any declared the first constructor, a constructor
the first constructors, statement in this() can be of a subclass
statement in the implicit the body of a declared as will always
the body of a default constructor, the second work, since all
constructor. constructor of this() will statement superclasses
the subclass implicitly be have a default
will call inserted as constructor.
super() when the first
run statement.
0 0 0
class Animal { MCQ run time error generic noise bark compile error 1 0
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.
0 0
Consider the code below & select the correct MCQ Canada Compilation Compiles but null 0 1
ouput from the options: error error at run
time
class Money {
private String country = "Canada";
public String getC() { return country; } }
class Yen extends Money {
public String getC() { return super.country; }
public static void main(String[] args) {
System.out.print(new Yen().getC() ); } } 0 0
Which Man class properly represents the MCQ A B C D 0 0
relationship "Man has a best friend who is a
Dog"?
A)class Man extends Dog { }
B)class Man implements Dog { }
C)class Man { private BestFriend dog; }
D)class Man { private Dog bestFriend; } 0 1
Consider the following code and choose the MCQ display Compilation Compiles but Runs but no 0 1
correct option: error error at run output
interface Output{ time
void display();
void show();
}
class Screen implements Output{
void show() {System.out.println("show");}
void display(){ System.out.println("display");
}public static void main(String[] args) {
new Screen().display();}}
0 0
The concept of multiple inheritance is MCQ (A) (A) & (C) (D) (B) & (C) 0 0
implemented in Java by

(A) extending two or more classes


(B) extending one class and implementing one
or more interfaces
(C) implementing two or more interfaces
(D) all of these 0 1
Consider the following code and choose the MCQ display Compilation Compiles but Runs but no 0 1
correct option: error error at run output
interface Output{ time
void display();
void show();
}
class Screen implements Output{
void display(){ System.out.println("display");
}public static void main(String[] args) {
new Screen().display();}}
0 0
Given a derived class method which overrides MCQ super this keyword by creating an cannot call 1 0
one of it’s base class methods. With derived keyword instance of the because it is
class object you can invoke the overridden base class overridden in
base method using: derived class 0 0
Consider the following code and choose the MCQ 150 mph Compilation 90 mph Compiles but 1 0
correct option: error error at
abstract class Car{ runtime
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();}} 0 0
Given the following classes and declarations, MCA The Bar class The statement The statement The statement 0.333333 0
which statements are true? is a subclass a.j = 5; is b.f(); is legal. a.g(); is legal.
// Classes of Foo. legal.
class Foo {
private int i;
public void f() { /* ... */ }
public void g() { /* ... */ }
}
class Bar extends Foo {
public int j;
public void g() { /* ... */ }
}
// Declarations:
Foo a = new Foo();
Bar b = new Bar(); 0.333333 0.333333
All data members in an interface are by default MCQ abstract and public and public ,static default and 0 0
final abstract and final abstract 1 0
Consider the given code and select the correct MCQ Compilation of Compilation of Compilation of Compilation of 0 0
output: both classes both classes class A will class B will
A & B will fail will succeed fail. fail.
class SomeException { Compilation of Compilation of
} class B will class A will
succeed succeed
class A {
public void doSomething() { }
}

class B extends A {
public void doSomething() throws
SomeException { }
} 0 1
Given: MCQ This is a final This is a final Compilation illegal Some 0 0
class A { method illegal method Some error error
final void meth() { error message
System.out.println("This is a final method."); message
}
}
class B extends A {
void meth() {
System.out.println("Illegal!");
}
}
class MyClass8{
public static void main(String[] args) {
A a = new A();
a.meth();
B b= new B();
b.meth();
}
}What would be the result?
1 0
Consider the code below & select the correct MCQ 000 47 7 0 Compilation 47 47 47 0 0
ouput from the options: error
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()); }}
0 1
Given: MCQ class AllMath interface abstract class class AllMath 0 0
interface DoMath extends AllMath AllMath implements
{ DoMath { implements implements MathPlus {
double getArea(int r); double MathPlus { DoMath, double
} getArea(int r); double MathPlus { getArea(int
interface MathPlus } getVol(int x, public double rad); }
{ int y); } getArea(int
double getVolume(int b, int h); rad) { return
} rad * rad *
/* Missing Statements ? */ 3.14; } }
Select the correct missing statements. 1 0
interface interface_1 { MCQ From F1 Compile time Create an Runtime Error 0 1
void f1(); function in error object for
} Class_1 Class Interface only
class Class_1 implements interface_1 {
void f1() {
System.out.println("From F1 funtion in
Class_1 Class");
}
}
public class Demo1 {
public static void main(String args[]) {
Class_1 o11 = new Class_1();
o11.f1();
}
} 0 0
interface A{} MCQ B b=c; A a2=(B)c; C c2=(C)(B)c; A a1=(Test)c; 0 0
class B implements A{}
class C extends B{}
public class Test extends C{
public static void main(String[] args) {
C c=new C();
/* Line6 */}}

Which code, inserted at line 6, will cause a


java.lang.ClassCastException? 0 1
Given the following classes and declarations, MCA The B class is The statement The statement The statement The statement 0.333333 0.333333
which statements are true? a subclass of b.f(); is legal a.j = 5; is a.g(); is legal b.i = 3; is
// Classes A. legal. legal.
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. 0 0.333333 0
Which of the following statements is true MCQ It can only be Only one child It must be It must be 0 0
regarding the super() method? used in the class can use used in the used in the
parent's it last statement first statement
constructor of the of the
constructor. constructor.
0 1
Is it possible if a class definition implements MCQ No—if a class No—a class Yes— either Yes—since 0 0
two interfaces, each of which has the same implements may not of the two the definitions
definition for the constant? several implement variables can are the same
interfaces, more than one be accessed it will not
each constant interface through : matter
must be interfaceNam
defined in only e.variableNa
one interface me

1 0
Consider the code below & select the correct MCQ 100 Compilation Compiles but Compiles but 1 0
ouput from the options: error error at run no output
time
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); }
public Alps(){ this(100); }
public static void main(String[] args) {
System.out.println(new Alps().getH());
}
} 0 0
Consider the following code and choose the MCQ sal details sal details per compilation per details sal 0 0
correct option: details error details
interface employee{
void saldetails();
void perdetails();
}
abstract class perEmp implements employee{
public void perdetails(){
System.out.println("per details"); }}
class Programmer extends perEmp{
public static void main(String[] args) {
perEmp emp=new Programmer();
emp.saldetails(); }}
1 0
Consider the following code and choose the MCQ Fun Time Compilation Fun Run Compiles but 0 0
correct option: error error at
abstract class Fun{ runtime
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(); }} 1 0
What will be the result when you try to compile MCQ Error at 200 100 followed 100 0 0
and run the following code? compile time by 200
class Base1 {
Base1() {
int i = 100;
System.out.println(i);
}
}

public class Pri1 extends Base1 {


static int i = 200;

public static void main(String argv[]) {


Pri1 p = new Pri1();
System.out.println(i);
}
} 1 0
What will be the output of the program? MCQ 4, 4 4, 5 5, 4 Compilation 0 0
fails
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)


{
SuperClass sp = new SuperClass();
SubClass sb = new SubClass();
System.out.println(
sp.getLength().toString() + "," +
sub.getLength().toString() );
}
} 0 1
What is the output for the following code: MCQ run time compile time hello hellohello 0 1
abstract class One{ exception error
private abstract void test();
}
class Two extends One{
void test(){
System.out.println("hello");
}}
class Test{
public static void main(String[] args){
Two obj = new Two();
obj.test();
}
} 0 0
What is the output : MCQ hello compile error runtime error none 0 1
interface A{
void method1();
void method2();
}
class Test implements A{
public void method1(){
System.out.println("hello");}}
class RunTest{
public static void main(String[] args){
Test obj = new Test();
obj.method1();
}} 0 0
What is the result of attempting to compile and MCQ 1 2 3 4 0 0
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 object comparison 3. Will run
and print "equal". 4. Will run and print "not
equal".
1 0
TreeSet<String> s = new TreeSet<String>(); MCA The size of s The size of s The size of The size of s The size of 0 0.5
TreeSet<String> subs = new is 4 is 5 subs is 3 is 7 subs is 1
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();
s.add("c2");
System.out.println(s.size() +" "+ subs.size());

0.5 0 0
Which collection class allows you to grow or MCQ java.util.Hash java.util.Linke java.util.List java.util.Array java.util.Vecto 0 0
shrink its size and provides indexed access to Set dHashSet List r
its elements, but its methods are not
synchronized?
0 1 0
Which statement is true about the following MCQ The program The program The program The program 0 0
program? will compile will compile will compile will not
import java.util.ArrayList; and print the and print the and throw a compile
import java.util.Collections; following following runtime
import java.util.List; output: [B] output: [B,A] exception
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())
;
System.out.println(list.subList(1,2));
}
} 1 0
static int binarySearch(List list, Object key) is a MCQ Vector class ArrayList Collection Collections 0 0
method of __________ class interface class 0 1
Given: MCQ 1 12 14 123 0 0
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]);
}
} What is the result? 1 0
static void sort(List list) method is part of MCQ Collection Collections Vector class ArrayList 0 1
________ interface class class 0 0
Consider the code below & select the correct MCQ 2 -4 3 -5 2 -6 3 -4 0 0
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");
int s2=Arrays.binarySearch(colors, "silver");
System.out.println(s1+" "+s2); }}

1 0
Consider the following code was executed on MCQ Wed Jun 01 244 JUN 01 PST JUN 01 GMT JUN 01 1 0
June 01, 1983. What will be the output? 1983 1983 1983 1983
class Test{
public static void main(String args[]){
Date date=new Date();
SimpleDateFormat sd;
sd=new SimplpeDateFormat("E MMM dd
yyyy");
System.out.print(sd.format(date));}} 0 0
Consider the following code and choose the MCQ 3 5 compilation Compiles but 0 1
correct option: error error at run
class Data{ Integer data; Data(Integer time
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));
s.add(new Data(2));
System.out.print(s.size());}} 0 0
next() method of Scanner class will return MCQ Integer Long int String 0 0
_________ 0 1
Given: MCQ 3, 2, 1, 1, 2, 3, Compilation The code runs 0 0
public static Iterator reverse(List list) { fails. with no
Collections.reverse(list); output.
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? 1 0
Given: MCQ true false Compile time Runtime 0 1
import java.util.Arrays; error Exception
import java.util.HashSet;
import java.util.Set;

public class MainClass {

public static void main(String[] a) {


String elements[] = { "A", "B", "C", "D", "E" };
Set set = new
HashSet(Arrays.asList(elements));

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


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

System.out.println(set.equals(set2));
}
} What is the result of given code?

0 0
import java.util.StringTokenizer; MCQ Today is Today is Both none of the 0 1
class ST{ Holiday Holiday listed options
public static void main(String[] args){
String input = "Today is$Holiday";
StringTokenizer st = new
StringTokenizer(input,"$");
while(st.hasMoreTokens()){
System.out.println(st.nextElement());
}} 0 0
int indexOf(Object o) - What does this method MCQ null -1 none of the 0 1
return if the element is not found in the List? listed options
0 0
Consider the following code and choose the MCQ Compilation prints 3,4,2,1, prints 1,2,3,4 Compiles but 0 0
correct option: error exception at
class Test{ runtime
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
A) It is a good practice to store heterogenous MCQ A and B is A and D is A and C is B and C is 0 0
data in a TreeSet. TRUE TRUE TRUE TRUE
B) HashSet has default initial capacity (16) and
loadfactor(0.75)
C)HashSet does not maintain order of
Insertion
D)TreeSet maintains order of Inserstion 0 1
Consider the following code and choose the MCQ [1,4,6,8] [1,8,6,4] [1,4,6,8,9] [1,4,6,8,9] 0 0
correct option: [4,6,8,9] [8,6,4,9] [4,6,8,9] [4,6,8]
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);
System.out.println(ss);
}} 1 0
Inorder to remove one element from the given MCQ tSet.clear(new tSetdelete(ne tSet.remove(n tSet.drop(new 0 0
Treeset, place the appropriate line of code Integer("1")); w ew Integer("1"));
public class Main { Integer("1")); Integer("1"));
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());
}
}
1 0
A)Property files help to decrease coupling MCQ A and B is A and D is A and C is B and D is 0 0
B) DateFormat class allows you to format dates TRUE TRUE TRUE TRUE
and times with customized styles.
C) Calendar class allows to perform date
calculation and conversion of dates and times
between timezones.
D) Vector class is not synchronized 1 0
Which interface does java.util.Hashtable MCQ Java.util.Map Java.util.List Java.util.Table Java.util.Colle 1 0
implement? ction 0 0
Consider the following code and choose the MCQ The before() The before() The before() The before() 0 0
correct option: method will method will method will method will
public static void before() { print 1 2 print 1 2 3 throw an not compile
Set set = new TreeSet(); exception at
set.add("2"); runtime
set.add(3);
set.add("1");
Iterator it = set.iterator();
while (it.hasNext())
System.out.print(it.next() + " ");
} 1 0
Given: MCQ Compilation aAaA aAa AAaa AaA AaA AAaa 0 0
import java.util.*; fails. AAaa AaA aAa aAaA aAaA aAa

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 + "
"); }
}
}
What is the result? 1 0
Which collection class allows you to access its MCQ java.util.Sorte java.util.Tree java.util.TreeS java.util.Hasht 0 0
elements by associating a key with an dMap Map et able
element's value, and provides synchronization?
0 1
Consider the following code and select the MCQ [1,3,2] [1,3,3,2] [1,3,2,1,3,2] [3,1,2] [3,1,1,2] 1 0
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);
}
}
0 0 0
Given: MCQ A, B, C, B, C, A, Compilation An exception 0 1
public static Collection get() { fails. is thrown at
Collection sorted = new LinkedList(); runtime.
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 + ", ");
}
}
What is the result? 0 0
You wish to store a small amount of data and MCQ 1 2 3 4 0 0
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
3) LinkedList
4) an array 0 1
Given: MCQ Compilation The code runs An exception Compilation Compilation 1 0
10. interface A { void x(); } fails because with no is thrown at fails because fails because
11. class B implements A { of an error in output. runtime of an error in of an error in
public void x() { } line 25 line 21 line 23.
public void y() { } }
12. class C extends B {
public void x() {} }
And:
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();
25. a.y();;
26. }
What is the result? 0 0 0
A) Iterator does not allow to insert elements MCQ A and B is A and D is A and C is B and D is 0 0
during traversal TRUE TRUE TRUE TRUE
B) Iterator allows bidirectional navigation.
C) ListIterator allows insertion of elements
during traversal
D) ListIterator does not support bidirectional
navigation 1 0
What will be the output of following code? MCQ [2,3,7,5] [2,3,4,5,6] [2,3,7,5,4,6] [2,3,4,5,6,7] 0 1
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);
ss.add(6);
System.out.print(ss);}}
0 0
Object get(Object key) - What does this MCQ -1 null none of the 0 0
method return if the key is not found in the listed options
Map? 1 0
Consider the following code and choose the MCQ {2=Two, {4=Four, {4=Four, {2=Two, 0 0
correct output: 4=Four, 6=Six, 6=Six} 4=Four,
class Test{ 6=Six, 7=Seven} 6=Six}
public static void main(String args[]){ 7=Seven}
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(4);
System.out.print(sm2);
}} 1 0
Which of the given options is similar to the MCQ value = value sum = sum + value = value value = value 1 0
following code: + sum; sum = 1; value = + sum; + ++sum;
sum + 1; value + sum;
value += sum++ ; 0 0
Which will legally declare, construct, and MCQ int [] myList = int [] myList = int myList [] [] int myList [] = 0 0
initialize an array? {"1", "2", "3"}; (5, 8, 2); = {4,9,7,0}; {4, 3, 7};
0 1
Consider the code below & select the correct MCQ Compilation The variable The variable Compiles but 0 0
ouput from the options: error first is set to first is set to error at
public class Test { null. elements[0]. runtime
public static void main(String[] args) {
String[] elements = { "for", "tea", "too" };
String first = (elements.length > 0)
?elements[0] : null;
System.out.println(first); }} 1 0
Consider the following code and choose the MCQ Hello World Compilation Compiles but Compiles but 1 0
correct option: error error at run run without
class Test{ time output
interface Y{
void display(); }
public static void main(String[] args) {
new Y(){
public void display(){
System.out.println("Hello World"); }
}.display(); }} 0 0
class Test{ MCQ 48 94 Compiles but Compilation 0 1
public static void main(String[] args){ error at run error
byte b=(byte) (45 << 1); time
b+=4;
System.out.println(b); }}
What should be the output for the code written
above? 0 0
What is the value of y when the code below is MCQ 1 2 3 4 0 0
executed?
int a = 4;
int b = (int)Math.ceil(a % 3 + a / 3.0); 1 0
Consider the following code and choose the MCQ Hello World Compilation Compiles but Compiles but 1 0
correct option: error error at run run without
class Test{ time output
interface Y{
void display(); }
public static void main(String[] args) {
Y y=new Y(){
public void display(){
System.out.println("Hello World"); } };
y.display(); }} 0 0
What is the output of the following program? MCQ A sequence of A sequence of compile time Compiles but 0 0
public class demo { five 10's are Garbage Error no output
public static void main(String[] args) { printed Values are
int arr[5]; printed
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]);

}
} 1 0
What will be the result of the following MCQ The program The program The program The program Compilation 0 0
program? will compile, will compile, will compile, will compile, error
public class Init { and print and print and print | and print
String title; |null|false|0|0. |null|true|0|0.0| |false|0|0.0|0.0 |null|false|0|0.
boolean published; 0|0.0|, when 100.0|, when |, when run 0|100.0|, when
static int total; run run run
static double maxPrice;
public static void main(String[] args) {
Init initMe = new Init();
double price;
if (true)
price = 100.00;
System.out.println("|" + initMe.title + "|" +
initMe.published + "|" +
Init.total + "|" + Init.maxPrice + "|" + price+ "|");
}
}
0 1 0
Consider the following code and choose the MCQ 4 Compilation Compiles but 1 0
correct option: error error at run
class Test{ time
static class A{
interface X{
int z=4; } }
static void display(){
System.out.println(A.X.z); }
public static void main(String[] args) {
display(); }} 0 0
Here is the general syntax for method MCQ The The If the The 0 0
definition: returnValue returnValue returnType is returnValue
must be can be any void then the must be the
accessModifier returnType methodName( exactly the type, but will returnValue same type as
parameterList ) same type as be can be any the
{ the returnType automatically type returnType, or
Java statements converted to be of a type
returnType that can be
return returnValue; when the converted to
} method returnType
returns to the without loss of
caller. information.
What is true for the returnType and the
returnValue? 0 1
class C{ MCQ compile time compile time prints 34,56 runtime none of the 0 1
public static void main (String[] args) { error at line 2 error at line 4 exception listed options
byte b1=33; //1
b1++; //2
byte b2=55; //3
b2=b1+1; //4
System.out.println(b1+""+b2);
}}
Consider the code above & select the correct
output. 0 0 0
What will be the output of the program? MCQ args[2] = 2 args[2] = 3 args[2] = null An exception 0 0
is thrown at
public class CommandArgs runtime
{
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);
}
}

and the command-line invocation is

> java CommandArgs 1 2 3 4 0 1


A) The purpose of the method overriding is to MCQ Only A is Only B is True Both A and B Both A and B 1 0
perform different operation, though input TRUE is True is FALSE
remains the same.
B) one of the important Object Oriented
principle is the code reusability that can be
achieved using abstraction 0 0
Consider the following code snippet: MCQ 10, 1 11, 1 10, 0 11 , 0 0 1
int i = 10;
int n = ++i%5;
What are the values of i and n after the code is
executed? 0 0
Consider the following code and choose the MCQ 3 Compilation Compiles but 0 1
correct option: error error at run
class Test{ time
class A{ static int x=3; }
static void display(){
System.out.println(A.x); }
public static void main(String[] args) {
display(); }} 0 0
Consider the following code and choose the MCQ value: 0 count: value: 0 count: value: 1 count: value: 1 count: 0 0
correct output: 0 1 1 2

int value = 0;
int count = 1;
value = count++ ;
System.out.println("value: "+ value + " count: "
+ count); 0 1
What will be the output of the program? MCQ 012 23 000 An exception 0 0
is thrown at
public class CommandArgsTwo runtime
{
public static void main(String [] argh)
{
int x;
x = argh.length;
for (int y = 1; y <= x; y++)
{
System.out.print(" " + argh[y]);
}
}
}

and the command-line invocation is

> java CommandArgsTwo 1 2 3 0 1


class Test{ MCQ compiles and var = 1 does not run time error 0 0
public static void main(String[] args){ runs with no compile
int var; output
var = var +1;
System.out.println("var ="+var);
}}
consider the code above & select the proper
output from the options. 1 0
Consider the following code and select the MCQ Hello World Compilation Compiles but Compiles but 0 0
correct output: error error at run run without
class Test{ time output
interface Y{
void display(); }
public static void main(String[] args) {
new Y(){
public void display(){
System.out.println("Hello World"); } };
}} 0 1
Which of the following will declare an array and MCQ Array a = new int [] a = int a [] = new int [5] array; 0 1
initialize it with five numbers? Array(5); {23,22,21,20,1 int[5];
9}; 0 0
Which three are legal array declarations? MCA int [] char [] int [6] Dog myDogs Dog myDogs 0.333333 0.333333
(Choose THREE) myScores []; myChars; myScores; []; [7]; 0 0.333333 0
What is the output of the following program? MCQ 13 13.5 13 Compilation Runtime Error 0 0
public class MyClass Error
{
public static void main( String[] args )
{
private static final int value =9;
float total;
total = value + value / 2;
System.out.println( total );
}
} 0 1 0
As per the following code fragment, what is the MCQ -1 4 random value 1 0
value of a?
String s;
int a;
s = "Foolish boy.";
a = s.indexOf("fool"); 0 0
Consider the code below & select the correct MCQ Compilation A A 0 1
ouput from the options: error ParseExceptio NumberForm
class Test{ n is thrown by atException is
public static void main(String[] args) { the parse thrown by the
parse("Four"); } method at parse method
static void parse(String s){ runtime at runtime
try {
double d=Double.parseDouble(s);
}catch(NumberFormatException nfe){
d=0.0; }finally{
System.out.println(d); } }} 0 0
Consider the code below & select the correct MCQ t7 t9 a9 Compilation 1 0
ouput from the options: error
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"); }
public static void main(String[] args) {
A a =new Test();
a.add();
System.out.print(a.a); }} 0 0
Consider the following code: MCQ x = -7, y = 1, z x = 3, y = 2, z x = 4, y = 1, z x = 4, y = 2, z 0 1
int x, y, z; =5 =6 =5 =6
y = 1;
z = 5;
x = 0 - (++y) + z++;
After execution of this, what will be the values
of x, y and z? 0 0
What will be the output of the program ? MCQ 10, 9, 8, 7, 6, 9, 8, 7, 6, 5, Compilation An exception 0 0
fails is thrown at
public class Test runtime
{
public static void main(String [] args)
{
signed int x = 10;
for (int y=0; y<5; y++, x--)
System.out.print(x + ", ");
}
} 1 0
Consider the following code snippet: MCQ 10, 1 11, 1 10, 0 11 , 0 0 0
int i = 10;
int n = i++%5;
What are the values of i and n after the code is
executed? 0 1
What is the output of the following: MCQ a: 9 b:11 a: 10 b: 9 a: 9 b:9 a: 0 b:9 0 0

int a = 0;
int b = 10;

a = --b ;
System.out.println("a: " + a + " b: " + b ); 1 0
Consider the given code and select the correct MCQ 26 282 Compiles but Compilation 0 1
output: error at run error
class Test{ time
public static void main(String[] args){
int num1 = 012;
int num2 = 0x110;
int sum =num1+=num2;
System.out.println("Ans = "+sum); }} 0 0
What will happen if you attempt to compile and MCQ 19 followed by 19 follwed by Compile time 10 followed by 1 0
run the following code? 11 20 error 1
Integer ten=new Integer(10);
Long nine=new Long (9);
System.out.println(ten + nine);
int i=1;
System.out.println(i + ten); 0 0
Which of the following are correct variable MCA int #ss; int 1ah; int _; int $abc; 0 0
names? (Choose TWO) 0.5 0.5
Which of the following lines of code will MCQ Line 1, Line 5 Line 5 Line 1, Line 3, Line 3 Line 4 0 1
compile without warning or error? Line 5
1) float f=1.3;
2) char c="a";
3) byte b=257;
4) boolean b=null;
5) int i=10; 0 0 0
Consider the code below & select the correct MCQ 23 13 2 3 1 0
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 )
System.out.print("1 ");
System.out.print("2 ");
if ((b2 = true) && b1 )
System.out.print("3 "); } 0 0
Consider the code below & select the correct MCQ disp X = 6 disp X = 5 disp X = 5 Compilation 0 1
ouput from the options: main X=6 main X=5 main X=6 error
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);
}
void disp(int x) {
System.out.println("disp X = "+x++);
}} 0 0
Given the following piece of code: MCQ 0 6 1 7 2 8 3 8 0 6 1 7 2 8 3 9 0 5 1 5 2 5 3 5 compilation 1 0
public class Test { fails
public static void main(String args[]) {
int i = 0, j = 5 ;
for( ; (i < 3) && (j++ < 10) ; i++ ) {
System.out.print(" " + i + " " + j );
}
System.out.print(" " + i + " " + j );
}
}
what will be the output? 0 0
Identify the statements that are correct: MCQ (A), (B) & (C) (A), (B), (C) & (C) & (D) (A) & (B) 1 0
(A) int a = 13, a>>2 = 3 (D)
(B) int b = -8, b>>1 = -4
(C) int a = 13, a>>>2 = 3
(D) int b = -8, b>>>1 = -4 0 0
Consider the following code and choose the MCQ Compilation Compiles but 4 0 1
correct option: error error at run
class Test{ time
class A{
interface X{
int z=4; } }
static void display(){
System.out.println(new A().X.z); }
public static void main(String[] args) {
display(); }} 0 0
Given MCQ 83886080 and 2 and 2 and - 83886080 and 0 0
class MybitShift -2 83886080 83886080 2
{
public static void main(String [] args)
{
int a = 0x5000000;
System.out.print(a + " and ");
a = a >>> 25;
System.out.println(a);
}
} 0 1
1. public class LineUp { MCQ A B C D 0 0
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|?

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


B. System.out.printf("|%3.7f| \n", d);
C. System.out.printf("|%7.3d| \n", d);
D. System.out.printf("|%7.3f| \n", d); 0 1
Here is the general syntax for method MCQ It must always It can be The access It can be 0 1
definition: be private or omitted, but if modifier must omitted, but if
public not omitted agree with the not omitted it
accessModifier returnType methodName( there are type of the must be
parameterList ) several return value private or
{ choices, public
Java statements including
private and
return returnValue; public
}

What is true for the accessModifier? 0 0


Given classes A, B, and C, where B extends A, MCQ It is not super.doIt() his.super.doIt( ((A) A.this.doIt() 1 0
and C extends B, and where all classes possible ) this).doIt();
implement the instance method void doIt().
How can the doIt() method in A be
called from an instance method in C? 0 0 0
State the class relationship that is being MCQ Aggregation Simple Dependency Composition 0 0
implemented by the following code: Association
class Employee
{
private int empid;
private String ename;
public double getBonus()
{
Accounts acc = new Accounts();
return acc.calculateBonus();
}
}

class Accounts
{
public double calculateBonus(){//method's
code}
} 1 0
Say that class Rodent has a child class Rat and MCQ rod = mos pkt = rat pkt = null rod = rat 0 1
another child class Mouse. Class Mouse has a
child class PocketMouse. Examine the
following

Rodent rod;
Rat rat = new Rat();
Mouse mos = new Mouse();
PocketMouse pkt = new PocketMouse();

Which one of the following will cause a


compiler error? 0 0
How many objects and reference variables are MCQ Two objects Three objects Four objects Two objects 1 0
created by the following lines of code? and three and two and two and two
Employee emp1, emp2; reference reference reference reference
emp1 = new Employee() ; variables. variables variables variables.
Employee emp3 = new Employee() ; 0 0
Consider the code below & select the correct MCQ 92 91 Compilation 82 0 0
ouput from the options: error

public class Test {


int squares = 81;
public static void main(String[] args) {
new Test().go(); }
void go() {
incr(++squares);
System.out.println(squares); }
void incr(int squares) { squares += 10; } } 0 1
Consider the following code and choose the MCQ false true 1 0 1
correct option:
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]"));}} 0 0
Consider the following code and choose the MCQ 10 27 24 11 0 1
correct option:
public class Test {
public static void main(String[] args) {
StringBuffer sb=new
StringBuffer("YamunaRiver");
System.out.println(sb.capacity()); }} 0 0
Examine this code: MCQ result = result.concat( result+stringA result = 1 0
stringA.concat stringA, +stringB+strin concat(String
String stringA = "Wild"; ( stringB, gC; A).concat(Stri
String stringB = " Irish"; stringB.concat stringC ); ngB).concat(S
String stringC = " Rose"; ( stringC ) ); tringC)
String result;

Which of the following puts a reference to


"Wild Irish Rose" in result? 0 0
A)A string buffer is a mutable sequence of MCQ Only A is Only B is Both A and B Both A and B 1 0
characters. TRUE TRUE is TRUE is FALSE
B) sequece of characters in the string buffer
can not be changed. 0 0
Consider the following code and choose the MCQ hi hi hi world world Compilation 1 0
correct option: error
class Test {
public static void main(String[] args) {
new Test().display(1,"hi");
new Test().display(2,"hi", "world" ); }
public void display(int x,String... s) {
System.out.print(s[s.length-x] + " "); }} 0 0
Consider the following code and choose the MCQ K A R I 0 0
correct option:
public class Test {
public static void main(String[] args) {
String name="vikaramaditya";
System.out.println(name.substring(2,
5).toUpperCase().charAt(2));}} 1 0
For two string objects obj1 and obj2: MCQ Only A is Only B is Both A and B Both A and B 0 0
A) Use of obj1 == obj2 tests whether two String TRUE TRUE is TRUE is FALSE
object references refer to the same object
B) obj1.equals(obj2) compares the sequence of
characters in obj1 and obj2.
1 0
What will be the result when you attempt to MCQ Compilation Compilation Compilation Compile time 0 0
compile and run the following code?. and output the and output the and output the error
public class Conv string "Hello" string "ello" string elloH
{
public static void main(String argv[]){
Conv c=new Conv();
String s=new String("ello");
c.amethod(s);
}

public void amethod(String s){


char c='H';
c+=s;
System.out.println(c);
}
} 0 1
Examine this code: MCQ result = result.concat( result+stringA result = 1 0
stringA.concat stringA, +stringB+strin concat(String
String stringA = "Hello "; ( stringB, gC; A).concat(Stri
String stringB = " World"; stringB.concat stringC ); ngB).concat(S
String stringC = " Java"; ( stringC ) ); tringC)
String result;
Which of the following puts a reference to
"Hello World Java" in result? 0 0
Consider the following code and choose the MCQ 203 204 205 Compilation 0 1
correct option: error
public class Test {
public static void main(String[] args) {
String name="vikaramaditya";
System.out.println(name.codePointAt(2)+name
.charAt(3)); }} 0 0
Consider the following code and choose the MCQ acctna iccratna ctna tna 0 0
correct option:
public class Test {
public static void main(String[] args) {
StringBuffer sb = new
StringBuffer("antarctica");
sb.reverse();
sb.replace(2, 7, "c");
sb.delete(0,2);
System.out.println(sb); }} 1 0
Which code can be inserted at Line X to print MCQ if(s==s2) if(s.equals(s2) if(s.equalsIgn if(s.noCaseMa if(s.equalIgnor 0 0
"Equal"? ) oreCase(s2)) tch(s2)) eCase(s2))
public class EqTest{
public static void main(String argv[]){
EqTest e=new EqTest();
}

EqTest(){
String s="Java";
String s2="java";
// Line X
{
System.out.println("Equal");
}else
{
System.out.println("Not equal");
}
}
} 1 0 0
Given: MCA Compilation The first line The first line The second The second 0 0
public class Theory { fails of output is of output is line of output line of output
public static void main(String[] args) { abc abc false abcd abc false is abcd abc is abcd abcd
String s1 = "abc"; false true
String s2 = s1;
s1 += "d";
System.out.println(s1 + " " + s2 + " " +
(s1==s2));

StringBuffer sb1 = new StringBuffer("abc");


StringBuffer sb2 = sb1;
sb1.append("d");
System.out.println(sb1 + " " + sb2 + " " +
(sb1==sb2));
}
}
Which are true? (Choose all that apply.) 0.5 0 0.5
Consider the following code and choose the MCQ bat at atm Compilation 0 1
correct option: error
class Test {
public static void main(String args[]) {
String name=new String("batman");
int ibegin=1;
char iend=3;
System.out.println(name.substring(ibegin,
iend));
}} 0 0
Consider the following code and choose the MCQ 78abc abc78 Compilation Compiles but 0 0
correct option: error exception at
public class Test { run time
public static void main(String[] args) {
String data="78";
System.out.println(data.append("abc")); }} 1 0
Given: MCQ 1 4 Compilation 0 0
String test = "This is a test"; fails.
String[] tokens = test.split("\s");
System.out.println(tokens.length);
What is the result? 0 1
Consider the following code and choose the MCQ acitcratna acitrcratna accircratna accrcratna 0 0
correct option:
public class Test {
public static void main(String[] args) {
StringBuffer sb = new
StringBuffer("antarctica");
sb.reverse();
sb.insert(4, 'r');
sb.replace(2, 4, "c");
System.out.println(sb); }} 0 1
Consider the following code and choose the MCQ hi hi hi world world Compilation 0 0
correct option: error
class Test {
public static void main(String[] args) {
new Test().display("hi", 1);
new Test().display("hi", "world", 2); }
public void display(String... s, int x) {
System.out.print(s[s.length-x] + " "); } } 0 1
What does this code write: MCQ abc def abc def ghi abc def + abc def +ghi 0 1

StringTokenizer stuff = new StringTokenizer(


"abc def+ghi", "+");
System.out.println( stuff.nextToken() );
System.out.println( stuff.nextToken() ); 0 0
Consider the following code and choose the MCQ abcdefabcdef none of the 0 0
correct option: abcabcDEFD abcdefabcDE listed options
class Test { EF F
public static void main(String args[]) {
String s1 = "abc";
String s2 = "def";
String s3 = s1.concat(s2.toUpperCase( ) );
System.out.println(s1+s2+s3); } } 1 0
Consider the following code and choose the MCQ 4 2 6 Compilation 1 0
correct option: error
public class Test {
public static void main(String[] args) {
String name="Anthony Gomes";
int a=111;
System.out.println(name.indexOf(a)); }} 0 0
class StringManipulation{ MCQ Cognizant Cognizant Cognizant Technology 0 0
public static void main(String[] args){ Technology Technology Solutions Solutions
String str = new String("Cognizant"); Solutions
str.concat(" Technology");
StringBuffer sbf = new StringBuffer("
Solutions");
System.out.println(str+sbf);
}}
consider the code above & select the proper
output from the options. 1 0
What is the result of the following: MCQ One ring to One ring to One ring to Different 1 0
rule them all, rule them all, rule them Starts
String ring = "One ring to rule them all,\n"; One ring to One ring to all,\n One ring
String find = "One ring to find them."; find them. find them. to find them.

if ( ring.startsWith("One") &&
find.startsWith("One") )
System.out.println( ring+find );
else
System.out.println( "Different Starts" ); 0 0
Consider the following code and choose the MCQ -6 6 Compilation 1 0
correct option: error
public class Test {
public static void main(String[] args) {
String name="Anthony Gomes";
System.out.println(name.replace('n',
name.charAt(3)).compareTo(name)); }} 0 0
Consider the following code and choose the MCQ The code will The program The program The program The program 0 0
correct option: fail to compile will print will print will print will print
class MyClass { because the str3str1str2,w str3,when run str3str1,when str3str2,when
String str1="str1"; expression hen run run run
String str2 ="str2"; str3.concat(str
String str3="str3"; 1) will not
str1.concat(str2); result in a
System.out.println(str3.concat(str1)); valid
} argument for
} the println()
method 0 1 0
Consider the following code and choose the MCQ tica anta Compilation Complies but 1 0
correct option: error exception at
public class Test { run time
public static void main(String[] args) {
StringBuffer sb = new
StringBuffer("antarctica");
sb.delete(0,6);
System.out.println(sb); }} 0 0
Consider the following code and choose the MCQ 788232 7914 Compilation Compiles but 1 0
correct option: error exception at
public class Test { run time
public static void main(String[] args) {
String data="7882";
data+=32; System.out.println(data); }} 0 0
class X2 MCQ 1 2 3 0 0
{
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 */
}
}

after line 11 runs, how many objects are


eligible for garbage collection? 1 0
Which statement is true? MCQ A B C D 0 0
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.
1 0
Which of the following allows a programmer to MCQ x.delete() x.finalize() Runtime.getR Only the 0 0
destroy an object x? untime().gc() garbage
collection
system can
destroy an
object. 0 1
Given : MCQ This is java Thi is java This i java Thi i java none of the 0 0
public class MainOne { listed options
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? 0 1 0
Consider the following code and choose the MCQ 1 2 3 0 1
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();
return mx; }}
After line 8 runs. how many objects are eligible
for garbage collection? 0 0
How can you force garbage collection of an MCQ Garbage Call Call Call Set all 1 0
object? collection System.gc() System.gc() Runtime.gc(). references to
cannot be passing in a the object to
forced reference to new
the object to values(null,
be garbage for example).
collected 0 0 0
Which statements describe guaranteed MCA An object is The finilize() The finalize() An object will The garbage 0 0
behaviour of the garbage collection and deleted as method will method will not be collector will
finalization mechanisms? (Choose TWO) soon as there eventually be never be garbage use a mark
are no more called on called more collected as and sweep
references every object than once on long as it algorithm
that denote an object possible for a
the object live thread to
access it
through a
reference. 0.5 0.5 0
Examine the following code: MCQ count < 9 count+1 <= 8 count < 8 count != 8 1 0

int count = 1;
while ( ___________ )
{
System.out.print( count + " " );
count = count + 1;
}
System.out.println( );

What condition should be used so that the code


prints:

12345678 0 0
Given: MCQ 2 24 234 246 0 1
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;
o = o + x;
}
System.out.println(o);
}
}
What is the result? 0 0
Consider the following code and choose the MCQ Compilation 1515 255 Compiles but 0 0
correct option: error error at run
class Test{ time
public static void main(String args[]){
String hexa = "0XFF";
int number = Integer.decode(hexa);
System.out.println(number); }} 1 0
Given: MCQ Compilation granite granite atom granite atom granite 0 0
class Atom { fails. granite atom granite
Atom() { System.out.print("atom "); }
}
class Rock extends Atom {
Rock(String type) { System.out.print(type); }
}
public class Mountain extends Rock {
Mountain() {
super("granite ");
new Rock("granite ");
}
public static void main(String[] a) { new
Mountain(); }
}
What is the result? 0 1
Which of the following statements about arrays MCQ Person[] p []; Person p[][] = Person[] p = Person p[5]; 0 0
is syntactically wrong? new new
Person[2][]; Person[5]; 0 1
Given: MCQ hi hi hi world world world Compilation 0 0
public class Barn { fails.
public static void main(String[] args) {
new Barn().go("hi", 1);
new Barn().go("hi", "world", 2);
}
public void go(String... y, int x) {
System.out.print(y[y.length - 1] + " ");
}
}
What is the result? 0 1
Given: MCQ 23 32 25 Compilation Runtine Error 0 0
int n = 10; Error
switch(n)
{
case 10: n = n + 1;
case 15: n = n + 2;
case 20: n = n + 3;
case 25: n = n + 4;
case 30: n = n + 5;
}
System.out.println(n);
What is the value of ’n’ after executing the
following code? 1 0 0
Given: MCQ 00 0001 000120 00012021 0 0
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;
}
}
System.out.println(o);
}
What is the result when the go() method is
invoked? 1 0
What will be the output of the program? MCQ 012 012122 Compilation Compilation 0 0
fails at line 11 fails at line 12.
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)
{
case y: System.out.print("0 "); /*
Line 11 */
case x-1: System.out.print("1 "); /*
Line 12 */
case x: System.out.print("2 "); /*
Line 13 */
}
}
}
} 1 0
Consider the following code and choose the MCQ Compilation Compiles but Five Three 1 0
correct output: error no output
class Test{
public static void main(String args[]){
int a=5;
if(a=3){
System.out.print("Three");}else{
System.out.print("Five");}}} 0 0
public void foo( boolean a, boolean b) MCQ If a is true and If a is true and If a is false If a is false 0 0
{ b is false then b is true then and b is false and b is true
if( a ) the output is the output is then the then the
{ "notB" "A && B" output is output is
System.out.println("A"); /* Line 5 */ "ELSE" "ELSE"
}
else if(a && b) /* Line 7 */
{
System.out.println( "A && B");
}
else /* Line 11 */
{
if ( !b )
{
System.out.println( "notB") ;
}
else
{
System.out.println( "ELSE" ) ;
}
}
}

What would be the result? 0 1


Consider the following code and choose the MCQ Compilation true false 1 0 0
correct option: error
class Test{
public static void main(String args[]){
Long l=0l;
System.out.println(l.equals(0));}} 1 0
Consider the following code and choose the MCQ true false compilation Compiles 0 1
correct output: error
class Test{
public static void main(String args[]){
boolean flag=true;
if(flag=false){
System.out.print("TRUE");}else{
System.out.print("FALSE");}}} 0 0
class Test{ MCQ R.T.Ponting C.H.Gayle Compile error none of the 0 0
public static void main(String[] args) { listed options
int x=-1,y=-1;
if(++x=++y)
System.out.println("R.T. Ponting");
else
System.out.println("C.H. Gayle");
}
}
consider the code above & select the proper
output from the options. 1 0
Given: MCQ 81 91 92 82 0 0
public class Batman {
int squares = 81;
public static void main(String[] args) {
new Batman().go();
}
void go() {
incr(++squares);
System.out.println(squares);
}
void incr(int squares) { squares += 10; }
}
What is the result? 0 1
Consider the following code and choose the MCQ 7 Compilation Compiles but None of the 0 1
correct option: error error at run listed options
class Test{ time
public static void main(String args[]){
int l=7;
Long L = (Long)l;
System.out.println(L); }} 0 0
public class SwitchTest MCQ value = 6 value = 4 value = 2 value = 8 0 0
{
public static void main(String[] args)
{
System.out.println("value =" + switchIt(4));
}
public static int switchIt(int x)
{
int j = 1;
switch (x)
{
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default: j++;
}
return j + x;
}
}
What will be the output of the program?
0 1
Given: MCQ An exception [608, 610, [608, 610, Compilation 1 0
import java.util.*; is thrown at 612, 629] 612, 629] fails.
public class Explorer3 { runtime. [608, 610, [608, 610]
public static void main(String[] args) { 629]
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, true);
subs.add(629);
System.out.println(s + " " + subs);
}
}
What is the result?

0 0
Consider the code below & select the correct MCQ 0001 000120 00012021 Compilation 0 1
ouput from the options: error
public class Test{
public static void main(String[] args) {
String num="";
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;
num=num+x+y;
}System.out.println(num);}} 0 0
What will be the output of the program? MCQ x=1 x=3 Compilation The code runs 0 0
int x = 3; fails. with no
int y = 1; output.
if (x = y) /* Line 3 */
{
System.out.println("x =" + x);
} 1 0
Given: MCQ r, t, t, r, e, o, Compilation An exception 0 0
public static void test(String str) { fails. is thrown at
int check = 4; runtime.
if (check = str.length()) {
System.out.print(str.charAt(check -= 1) +", ");
} else {
System.out.print(str.charAt(0) + ", ");
}
}
and the invocation:
test("four");
test("tee");
test("to");
What is the result?
1 0
Which collection implementation is suitable for MCQ TreeMap HashSet Vector LinkedList ArrayList 0 0
maintaining an ordered sequence of
objects,when objects are frequently inserted in
and removed from the middle of the sequence?
0 1 0
11. double input = 314159.26; MCQ b = nf.parse( b = nf.format( b = nf.equals( b = 0 1
12. NumberFormat nf = input ); input ); input ); nf.parseObjec
NumberFormat.getInstance(Locale.ITALIAN); t( input );
13. String b;
14. //insert code here

Which code, inserted at line 14, sets the value


of b to 314.159,26? 0 0
int I = 0; MCQ 3 2 4 1 0 0
outer:
while (true)
{
I++;
inner:
for (int j = 0; j < 10; j++)
{
I += j;
if (j == 3)
continue inner;
break outer;
}
continue outer;
}
System.out.println(I);

What will be thr result? 0 1


What is the range of the random number r MCQ 2 <= r <= 9 3 <= r <= 10 2<= r <= 10 3 <= r <= 9 1 0
generated by the code below?
int r = (int)(Math.floor(Math.random() * 8)) + 2;
0 0
Which of these statements are true? MCA HashTable is ArrayList is a LinkedList is a Stack is a 0.5 0
a sub class of sub class of subclass of subclass of
Dictionary Vector ArrayList Vector 0 0.5
public class While MCQ There are There are There is a There is a 0 0
{ syntax errors syntax errors syntax error syntax error
public void loop() on lines 1 and on lines 1, 6, on line 6 on line 1
{ 6 and 8
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x +
1)); /* Line 8 */
}
}
}

Which statement is true? 1 0


Cosider the following code and choose the MCQ Compilation 2.147483648E NumberForm Compiles but 0 0
correct option: error 9 atException at no output
class Test{ run time
public static void main(String args[]){
System.out.println(Integer.parseInt("214748364
8", 10));
}} 1 0
class AutoBox { MCQ No, Yes, 10, 100 No, Runtime Yes, 100, 100 0 0
public static void main(String args[]) { Compilation error
error
int i = 10;
Integer iOb = 100;
i = iOb;
System.out.println(i + " " + iOb);
}
} whether this code work properly, if so what
would be the result? 0 1
Consider the following code and choose the MCQ 5,6 6,5 5,5 6,6 0 0
correct output:
public class Test{
public static void main(String[] args) {
int x = 0;
int y = 10;
do {
y--;
++x;
} while (x < 5);
System.out.print(x + "," + y);
}
} 1 0
Which of the following loop bodies DOES MCQ s += i * i; s++; s = s + s * i; s *= i; Compilation 0 0
compute the product from 1 to 10 like (1 * 2 * 3 error
*4*5*
6 * 7 * 8 * 9 * 10)?
int s = 1;
for (int i = 1; i <= 10; i++)
{
<What to put here?>
} 0 1 0
Which of the following statements are true MCA String is a Double has a Character has Byte extends String is the 0 0.5
regarding wrapper classes? (Choose TWO) wrapper class compareTo() a intValue() Number wrapper class
method method of char
0 0.5 0
import java.util.SortedSet; MCQ tSet.headSet tset.headset headSet HeadSet 1 0
import java.util.TreeSet;

public class Main {

public static void main(String[] args) {


TreeSet<String> tSet = new
TreeSet<String>();
tSet.add("1");
tSet.add("2");
tSet.add("3");
tSet.add("4");
tSet.add("5");
SortedSet sortedSet =_____________("3");
System.out.println("Head Set Contains : " +
sortedSet);
}
} What is the missing method in the code to get
the head set of the tree set?
0 0
What will be the output of following code? MCQ one two three four three two four one three one two three 0 0
four one two four one
TreeSet map = new TreeSet();
map.add("one");
map.add("two");
map.add("three");
map.add("four");
map.add("one");
Iterator it = map.iterator();
while (it.hasNext() )
{
System.out.print( it.next() + " " );
} 1 0
Consider the following code and choose the MCQ 23 Compilation Compiles but None of the 0 1
correct option: error error at run listed options
class Test{ time
public static void main(String args[]){
Long data=23;
System.out.println(data); }} 0 0
Which statements are true about maps? MCA The return Changes The Map All keys in a All Map 0 0.5
(Choose TWO) type of the made in the interface map are implementatio
values() Set view extends the unique ns keep the
method is set returned by Collection keys sorted
keySet() will interface
be reflected in
the original
map 0 0.5 0
Given: MCQ harrier shepherd retriever Compilation 0 0
public class Test { fails.
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 ");
case harrier:
System.out.print("harrier ");
}
}
}
What is the result? 0 1
Consider the following code and choose the MCQ 0 null Compiles but Compilation null 0 0 1
correct option: error at run error
class Test{ time
public static void main(String args[]){
Long L = null; long l = L;
System.out.println(L);
System.out.println(l);
}} 0 0
Consider the following code and choose the MCQ bat man Compilation bat man spider man 0 0
correct output: error spider man
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 0
Which of the following statements is TRUE MCQ An overflow A continue A loop may If a variable of 0 0
regarding a Java loop? error can only statement have multiple type int
occur in a doesn’t exit points overflows
loop transfer during the
control to the execution of a
test statement loop, it will
of the for loop cause an
exception 1 0
What is the value of ’n’ after executing the MCQ 14 28 Compilation 10 Runtime Error 0 0
following code? Error
int n = 10;
int p = n + 5;
int q = p - 10;
int r = 2 * (p - q);
switch(n)
{
case p: n = n + 1;
case q: n = n + 2;
case r: n = n + 3;
default: n = n + 4;
} 1 0 0
Given: MCQ very short average tall tall short short 0 0
double height = 5.5;
if(height-- >= 5.0)
System.out.print("tall ");
if(--height >= 4.0)
System.out.print("average ");
if(height-- >= 3.0)
System.out.print("short ");
else
System.out.print("very short ");
}
What would be the Result? 0 1 0
Consider the following code and choose the MCQ 2211 3 2 1 null 4211 3211 0 1
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");
tree.put(4,"Four");
System.out.println(tree.higherKey(2));
System.out.println(tree.ceilingKey(2));
System.out.println(tree.floorKey(1));
System.out.println(tree.lowerKey(1));
}} 0 0
What is the output of the following code : MCQ good good morning compiler error runtime error 0 0
class try1{ morning ….
public static void main(String[] args) {
System.out.println("good");
while(false){
System.out.println("morning");
}
}
} 1 0
Consider the following code and choose the MCQ default default compilation brownie 0 0
correct output: brownie error
class Test{
public static void main(String args[]){
int num='b'; switch(num){
default :{
System.out.print("default");}
case 100 : case 'b' : case 'c' : {
System.out.println("brownie"); break;}
case 200: case 'e': {
System.out.println("pastry"); }break; } }} 0 1
What does the following code fragment write to MCQ You win You lose You win the You lose the 0 0
the monitor? prize prize.

int sum = 21;


if ( sum != 20 )
System.out.print("You win ");
else
System.out.print("You lose ");

System.out.println("the prize.");

What does the code fragment prints? 1 0


what will be the result of attempting to compile MCQ The code will The code will The code will The code will The code will 0 0
and run the following class? fail to compile fail to compile compile compile compile
Public class IFTest{ because the because the correctly and correctly and correctly,but
public static void main(String[] args){ syntax of the if compiler will display the display the will not display
int i=10; statement is not be able to letter a,when letter b,when any output
if(i==10) incorrect determine run run
if(i<10) which if
System.out.println("a"); statement the
else else clause
System.out.println("b"); belongs to
}} 0 1 0
Given: MCQ 20 21 22 23 24 0 0
static void myFunc()
{
int i, s = 0;
for (int j = 0; j < 7; j++) {
i = 0;
do {
i++;
s++;
} while (i < j);
}
System.out.println(s);
}
} What would be the result 1 0 0
Choose TWO correct options: MCA To write an To write OutputStream Subclasses of 0 0
object to a file, characters to is the abstract the class
you use the an superclass of Reader are
class outputstream, all classes used to read
ObjectFileWrit you have to that represent character
er make use of an streams.
the class outputstream
CharacterOut of bytes.
putStream. 0.5 0.5
Consider the following code and choose the MCQ compilation apple default default apple 0 1
correct output: error
class Test{
public static void main(String args[]){
int num=3; switch(num){
default :{
System.out.print("default");}
case 1: case 3: case 4: {
System.out.println("apple"); break;}
case 2: case 5: {
System.out.println("black berry"); }break; }
}} 0 0
switch(x) MCQ 2 and 4 1 ,3 and 5 3 and 5 4 and 6 0 1
{
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 0 0
What is the output : MCQ M.S.Dhoni all of these Virat Kohli M.S.Dhoni 1 0
class One{ Sachin Virat
public static void main(String[] args) { Kohli
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");}
} 0 0
What is the output : MCQ none of the runtime error compiler error success 0 0
class Test{ listed options
public static void main(String[] args) {
int a=5,b=10,c=1;
if(a>c){
System.out.println("success");
}
else{
break;
}
}
} 1 0
Consider the following code and choose the MCQ Compiles but 46 compilation 40 0 0
correct option: error at run error
class Test{ time
public static void main(String args[]){ int
x=034;
int y=12;
int ans=x+y;
System.out.println(ans);
}} 0 1
Given: MCQ collie harrier Compilation collie harrier 0 0
public class Test { fails.
public enum Dogs {collie, harrier};
public static void main(String [] args) {
Dogs myDog = Dogs.collie;
switch (myDog) {
case collie:
System.out.print("collie ");
case harrier:
System.out.print("harrier ");
}
}
}
What is the result? 0 1
What will be the output of following code? MCQ Prints: false, Prints: false, Prints: false, Prints: false, 0 0
false, false false, true true, false true, true
import java.util.*;
class I
{
public static void main (String[] args)
{
Object i = new ArrayList().iterator();
System.out.print((i instanceof List)+",");
System.out.print((i instanceof
Iterator)+",");
System.out.print(i instanceof ListIterator);
}
}

1 0
public class Test { MCQ 123 3 2 23 0 0
public static void main(String [] args) {
int x = 5;
boolean b1 = true;
boolean b2 = false;

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


System.out.print("1 ");
System.out.print("2 ");
if ((b2 = true) && b1 )
System.out.print("3 ");
}
}
What is the result? 0 1
Given: MCQ 9 5 3 11 7 0 0
int a = 5;
int b = 5;
int c = 5;
if (a > 3)
if (b > 4)
if (c > 5)
c += 1;
else
c += 2;
else
c += 3;
c += 4;
What is the value of variable c after executing
the following code? 0 1 0
Given: MCQ Compilation pi is bigger An exception pi is bigger 1 0
Float pi = new Float(3.14f); fails. than 3. occurs at than 3. Have a
if (pi > 3) { runtime. nice day.
System.out.print("pi is bigger than 3. ");
}
else {
System.out.print("pi is not bigger than 3. ");
}
finally {
System.out.println("Have a nice day.");
}
What is the result? 0 0
Consider the following code and choose the MCQ Compilation j = -1 j=0 j=1 1 0
correct option: fails
int i = l, j = -1;
switch (i)
{
case 0, 1: j = 1;
case 2: j = 2;
default: j = 0;
}
System.out.println("j = " + j); 0 0
What is the output : MCQ run time error good compile error bad 0 0
class try1{
public static void main(String[] args) {
int x=1;
if(x--)
System.out.println("good");
else
System.out.println("bad");
}
} 1 0
Given: MCQ 5,6 5,5 6,5 6,6 0 1
int x = 0;
int y = 10;
do {
y--;
++x;
} while (x < 5);
System.out.print(x + "," + y);
What is the result? 0 0
What are the thing to be placed to complete the MCQ int, int Integer, new Integer, int int, Integer 0 1
code?
class Wrap {
public static void main(String args[]) {

_______________ iOb = ___________


Integer(100);

int i = iOb.intValue();

System.out.println(i + " " + iOb); // displays


100 100
}
} 0 0
Which of the following options give the valid MCA dollorpack.$p $$.$$.$$ _score.pack._ p@ckage.sub .package.sub 0.333333 0.333333
package names? (Choose 3) ack.$$pack _pack p@ckage.inne package.inner
rp@ckage package 0.333333 0 0
The term 'Java Platform' refers to MCQ Java Compiler Java Runtime Java Java 0 1
________________. (Javac) Environment Database Debugger
(JRE) Connectivity
(JDBC) 0 0
Which of the following statement gives the use MCQ Holds the Holds the Holds the Holds the 0 0
of CLASSPATH? location of location of location of location of
Core Java Java User Defined Java Software
Class Library Extension classes,
(Bootstrap Library packages and
classes) JARs 1 0
Which of the following options give the valid MCA String[] args String args[] String [][]args String args String[] args[] 0.5 0.5
argument types for main() method? (Choose 2)
0 0 0
Which of the following are true about MCA Packages can Packages can Packages can Sub packages Class and 0 0.5
packages? (Choose 2) contain only contain both contain non- should be Interfaces in
Java Source Classes and java elements declared as the sub
files Interfaces such as private in packages will
(Compiled images, xml order to deny be
Classes) files etc. importing automatically
them available to
the outer
packages
without using
import
statement. 0.5 0 0
Which of the following statements are true MCA Object class is Object class Object class Object class Object class 0 0
regarding java.lang.Object class? (Choose 2) an abstract cannot be has the core provides the implements
class instantiated methods for method for Serializable
directly thread Set interface
synchronizatio implementatio internally
n n in Collection
framework
0.5 0.5 0
Which of the following option gives one MCQ To maintain Helps the Helps JVM to Helps 0 1
possible use of the statement 'the name of the the uniform compiler to find and Javadoc to
public class should match with its file name'? standard find the execute the build the Java
source file classes Documentatio
that n easily
corresponds
to a class,
when it does
not find a
class file while
compiling
0 0
Consider the following code and choose the MCQ compilation will display Hi will create two will not create 0 0
correct option: error once child threads any child
class Cthread extends Thread{ and display Hi thread
Cthread(){start();} twice
public void run(){
System.out.print("Hi");}
public static void main (String args[]){
Cthread th1=new Cthread();
Cthread th2=new Cthread();
}} 1 0
public class MyRunnable implements MCQ new new new new 0 0
Runnable Thread(MyRu MyRunnable() Runnable(My Thread(new
{ nnable).run(); .start(); Runnable).sta MyRunnable()
public void run() rt(); ).start();
{
// some code here
}
}
which of these will create and start this thread?
0 1
Consider the following code and choose the MCQ will not create Will create will display Hi compilation 1 0
correct option: any child two child once error
class Nthread extends Thread{ thread threads and
public void run(){ display Hi
System.out.print("Hi");} twice
public static void main(String args[]){
Nthread th1=new Nthread();
Nthread th2=new Nthread();
} 0 0
Consider the following code and choose the MCQ will print Hi will print Hi Compilation will print Hi 0 1
correct option: twice and Thrice error once
class Cthread extends Thread{ throws
public void run(){ Exception at
System.out.print("Hi");} run time
public static void main (String args[]){
Cthread th1=new Cthread();
th1.run();
th1.start();
th1.run();
}} 0 0
The following block of code creates a Thread MCQ public class public class public class public class 0 0
using a Runnable target: MyRunnable MyRunnable MyRunnable MyRunnable
extends implements extends implements
Runnable target = new MyRunnable(); Runnable{pub Runnable{void Object{public Runnable{pub
Thread myThread = new Thread(target); lic void run(){}} void run(){}} lic void
run(){}} run(){}}
Which of the following classes can be used to
create the target, so that the preceding code
compiles correctly? 0 1
What will be the output of the program? MCQ Prints "Inside Prints "Inside Does not Throws 1 0
Thread Inside Thread Inside compile exception at
class MyThread extends Thread Thread" Runnable" runtime
{
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();
}
}
0 0
Which of the following methods are defined in MCA run() notify() terminate() wait() start() 0.5 0
class Thread? (Choose TWO) 0 0 0.5
wait(), notify() and notifyAll() methods belong to MCQ Thread class none of the Interrupt class Object class 0 0
________ listed options 0 1
Consider the following code and choose the MCQ It will start a compilation Compiles but a1 is not a 0 0
correct option: new thread error throws run Thread
class A implements Runnable{ int k; time
public void run(){ Exception
k++; }
public static void main(String args[]){
A a1=new A();
a1.run();} 0 1
class Cthread extends Thread{ MCQ will print Hi will print Hi will not print will start two 1 0
public void run(){ twice and Once thread
System.out.print("Hi");} throws
public static void main (String args[]){ exception at
Cthread th1=new Cthread(); runtime
th1.run();
th1.start();
th1.start();
}} 0 0
What will be the output of the program? MCQ Compilation An exception It prints The output 0 1
fails occurs at "Thread one. cannot be
class MyThread extends Thread runtime. Thread two." determined.
{
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 ");
}
} 0 0
class PingPong2 { MCQ The output The output The output The output 0 0
synchronized void hit(long n) { could be 6-1 6- could be 5-1 6- could be 6-1 5- could be 6-1 6-
for(int i = 1; i < 3; i++) 2 5-1 7-1 1 6-2 5-2 2 6-2 5-1 2 5-1 5-2
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()); }
}
Which statement is true? 0 1
Given: MCQ Compilation The code An exception The code 0 0
public class Threads4 { fails. executes is thrown at executes
public static void main (String[] args) { normally, but runtime. normally and
new Threads4().go(); nothing is prints "run".
} printed.
public void go() {
Runnable r = new Runnable() {
public void run() {
System.out.print("run");
}
};
Thread t = new Thread(r);
t.start();
t.start();
}
}
What is the result? 1 0
A) Multiple processes share same memory MCQ Only C and D Only A and B Only B and C All are FALSE 0 0
location is TRUE is TRUE is TRUE
B) Switching from one thread to another is
easier than switching from one process to
another
C) Thread makes it possible to maximize
resource utilization
D) Process is a light weight program 1 0
Which of the following methods registers a MCQ start(); register(); construct(); run(); 1 0
thread in a thread scheduler? 0 0
Which of the following statements can be used MCA Implement Implement Implement Extend Extend 0 0
to create a new Thread? (Choose TWO) java.lang.Thre java.lang.Thre java.lang.Run java.lang.Thre java.lang.Run
ad and ad and nable and ad and nable and
implement the implement the implement the override the override the
run() method. start() run() method run() method. start()
method. method. 0.5 0.5 0
class Thread2 { MCQ An exception Compilation The code prints Good 0 0
public static void main(String[] args) { is thrown at fails. executes Day.. Twice
new Thread2().go(); } runtime. normally and
public void go(){ prints "Good
Runnable rn=new Runnable(){ Day.."
public void run(){
System.out.println("Good Day.."); } };
Thread t=new Thread(rn);
t.start();
}}
what should be the correct output for the code
written above? 1 0
Assume the following method is properly MCQ After thread A Two seconds Two seconds After the lock 1 0
synchronized and called from a thread A on an is notified, or after thread A after lock B is on B is
object B: after two is notified. released. released, or
seconds. after two
wait(2000); seconds.

After calling this method, when will the thread A


become a candidate to get another turn at the
CPU? 0 0
A) Exception is the superclass of all errors and MCQ Both A and B Only B is Only A is Both A and B 0 1
exceptions in the java language are TRUE TRUE TRUE are FALSE
B) RuntimeException and its subclasses are
unchecked exception. 0 0
Select the variable which are in MCA METHOD SOURCE CLASS RUNTIME CONSTRUCT 0 0.333333
java.lang.annotation.RetentionPolicy class. OR
(Choose THREE) 0.333333 0.333333 0
Custom annotations can be created using MCQ @interface @inherit @include all the listed 1 0
options 0 0
Choose the meta annotations. (Choose MCA Override Retention Depricated Documented Target 0 0.333333
THREE) 0 0.333333 0.333333
All annotation types should maually extend the MCQ true false 0 1
Annotation interface. State TRUE/FALSE

If no retention policy is specified for an MCQ method class source runtime 0 1


annotation, then the default policy of
__________ is used. 0 0
Select the Uses of annotations. (Choose MCA Information Information Compile time Runtime Information 0.333333 0
THREE) For the for the JVM and processing for the OS
Compiler deploytime
processing 0.333333 0.333333 0
Which of the following is not an attribute of MCQ State Behaviour Inheritance Identity 0 0
object? 0 1
What is the advantage of runtime MCQ Efficient Code reuse Code flexibility avoiding 0 0
polymorphism? utilization of at runtime method name
memory at confusion at
runtime runtime 1 0
Which of the following is an example of IS A MCQ Ford - Car Microprocess Tea -Cup Driver -Car 1 0
relationship? or - Computer 0 0
Which of following set of functions are example MCQ void add(int char add(float void add(int void add(int 0 0
of method overloading x,int y) char x) char x,int y) char x,int y) void
add(int x,int y) add(float y) add(char sum(double
x,char y) x,double y) 1 0
Which of the following is not a valid relation MCQ Composition Inheritance Instantiation Segmentation 0 0
between classes? 0 1
Choose the correct option: MCQ A try Multiple catch An Error that Except in 0 0
statement statements might be case of VM
must have at can catch the thrown in a shutdown, if a
least one same class of method must try block starts
corresponding exception be declared to execute, a
catch block more than as thrown by corresponding
once. that method, finally block
or be handled will always
within that start to
method. execute.
0 1
consider the code & choose the correct output: MCQ End of java.lang.Runt End of run 0 0
class Threads2 implements Runnable { method. imeException: method. run. java.lang.Runt
java.lang.Runt Problem java.lang.Runt imeException:
public void run() { imeException: imeException: Problem
System.out.println("run."); Problem Problem
throw new RuntimeException("Problem");
}
public static void main(String[] args) {
Thread t = new Thread(new Threads2());
t.start();
System.out.println("End of method.");
}
}
1 0
Consider the following code: MCQ Code output: Code output: Code output: The code will 0 0
Start Hello Start Hello Start Hello not compile.
System.out.print("Start "); world End of world Catch world File Not
try file exception. Here File not Found
{ found.
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");
}

given that EOFException and


FileNotFoundException are both subclasses of
IOException. If this block of code is pasted in a
method, choose the best option. 0 1
Given: MCQ throw throws No code is throws 0 1
public class ExceptionTest Exception Exception necessary RuntimeExce
{ ption
class TestException extends Exception {}
public void runTest() throws TestException {}
public void test() /* Line X */
{
runTest();
}
}
At Line X, which code is necessary to make the
code compile?
0 0
Consider the following code and choose the MCQ Compilation ParseExceptio NumberForm 1 0
correct option: fails n thrown at atException
class Test{ runtime thrown at
public static void parse(String str) { runtime
try { int num = Integer.parseInt(str);
} catch (NumberFormatException nfe) {
num = 0; } finally {
System.out.println(num);
} } public static void main(String[] args) {
parse("one"); } 0 0
Which of the following statements is true? MCQ Any statement Any statement catch(X x) can The Error 0 0
that can throw that can throw catch class is a
an Error must an Exception subclasses of RuntimeExce
be enclosed in must be X where X is a ption.
a try block. enclosed in a subclass of
try block. Exception.

1 0
class Trial{ MCQ One Two One Catch One Catch One Two 0 0
public static void main(String[] args){ Catch Finally Finally Catch
try{
System.out.println("One");
int y = 2 / 0;
System.out.println("Two");
}
catch(RuntimeException ex){
System.out.println("Catch");
}
finally{
System.out.println("Finally");
}
}} 1 0
State True or False: MCQ True False 1 0
The main() method of a program can declare
that it throws checked exception.
Given: MCQ Compilation finally finally null 0 1
static void test() { fails. exception
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 "); }
}
What is the result? 0 0
Which statement is true? MCQ The notifyAll() To call The notify() The notify() 1 0
method must sleep(), a method is method
be called from thread must defined in causes a
a own the lock class thread to
synchronized on the object java.lang.Threimmediately
context ad release its
locks. 0 0
Which of the following is a checked exception? MCQ Arithmetic IOException NullPointerEx ArrayIndexOut 0 1
Exception ception OfBoundsExc
eption 0 0
Given: MCQ true Not true An exception none 1 0
public void testIfA() { is thrown at
if (testIfB("True")) { runtime.
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? 0 0
Given the following program,which statements MCQ If run with no If run with no The program If run with one 0 1
is true? arguments,the arguments,the will throw an arguments,the
Public class Exception { program will program will ArrayIndexOut program will
public static void main(String[] args) { produce no produce "The OfBoundsExc simply print
try { output end" eption the given
if(args.length == 0) return; argument
System.out.println(args[0]);
}finally {
System.out.println("The end");
}}} 0 0
Consider the following code and choose the MCQ none of the runtime error does not compiles 0 1
correct option: listed options compile successfully
int array[] = new int[10];
array[-1] = 0; 0 0
class PropagateException{ MCQ Arithmetic Runtime Arithmetic compilation 0 0
public static void main(String[] args){ Exception Exception Exception error
try{ Runtime
method(); Exception
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;
}}
consider the code above & select the proper
output from the options. 1 0
Which statement is true? MCQ A static If a class has Variables can When a 0 1
method synchronized be protected thread sleeps,
cannot be code, multiple from it releases its
synchronized. threads can concurrent locks
still access access
the problems by
nonsynchroniz marking them
ed code. with the
synchronized
keyword. 0 0
What is wrong with the following code? MCQ Since the A try block An empty A catch block A finally block 0 0
method foo() cannot be catch block is cannot follow must always
Class MyException extends Exception{} does not catch followed by not allowed a finally block follow one or
public class Test{ the exception both a catch more catch
public void foo() { generated by and a finally blocks
try { the method block
bar(); baz(),it must
} finally { declare the
baz(); RuntimeExce
} catch(MyException e) {} ption in a
} throws clause
public void bar() throws MyException {
throw new MyException();
}
public void baz() throws RuntimeException {
throw new RuntimeException();
}
} 0 1 0
The exceptions for which the compiler doesn’t MCQ Checked Unchecked Exception all of these 0 1
enforce the handle or declare rule exceptions exceptions 0 0
Consider the following code and choose the MCQ caught exit exit Compilation exit 0 1
correct option: RuntimeExce fails
class Test{ ption thrown
static void display(){ at run time
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");}
finally{ System.out.println("exit");}}}} 0 0
class X implements Runnable MCQ Thread t = Thread t = X run = new Thread t = 0 0
{ new Thread(); new X(); Thread t = new
public static void main(String args[]) x.run(); Thread(X); new Thread(X);
{ Thread(run); t.start();
/* Missing code? */ t.start();
}
public void run() {}
}
Which of the following line of code is suitable to
start a thread ? 1 0
Which two can be used to create a new MCA Implement Extend Implement Extend Implement 0.5 0.5
Thread? java.lang.Run java.lang.Thre java.lang.Thre java.lang.Run java.lang.Thre
nable and ad and ad and nable and ad and
implement the override the implement the override the implement the
run() method. run() method. start() start() run() method.
method. method. 0 0 0
Which four can be thrown using the throw MCQ 1, 4, 5 and 6 1, 2, 3 and 4 2, 4, 5 and 6 2, 3, 4 and 5 1 0
statement?

1.Error
2.Event
3.Object
4.Throwable
5.Exception
6.RuntimeException 0 0
Which of the following statements regarding MCA static methods static methods static methods static methods 0 0.5
static methods are correct? (2 answers) are difficult to can be called are always do not have
maintain, using an public, direct access
because you object because they to non-static
can not reference to are defined at methods
change their an object of class-level. which are
implementatio the class in defined inside
n. which this the same
method is class.
defined.
0 0.5
In the given code snippet MCA ClassCastExc NumberForm IllegalStateEx IllegalArgume 0 0.5
try { int a = Integer.parseInt("one"); } eption atException ception ntException
what is used to create an appropriate catch
block? (Choose all that apply.)
A. ClassCastException
B. IllegalStateException
C. NumberFormatException
D. IllegalArgumentException 0 0.5
Which of the following methods are static? MCA sleep() yield() join() start() 0.5 0.5 0 0
class Trial{ MCQ Try Block Try Block Finally Block Finally Block 1 0
public static void main(String[] args){ Finally Block Try Block
try{
System.out.println("Try Block");
}
finally{
System.out.println("Finally Block");
}
}} 0 0
class Animal { public String noise() { return MCQ bark meow Compilation An exception peep 0 0
"peep"; } } fails is thrown at
class Dog extends Animal { runtime.
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());
}}
consider the code above & select the proper
output from the options. 0 1 0
Consider the following code and choose the MCQ caught exit exit Compilation Compiles but 0 0
correct option: fails exception at
class Test{ runtime
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");}}} 0 1
Consider the following code and choose the MCQ test end test runtime test exception test exception 0 0
correct option: end runtime end end
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"); } } 0 1
class Test{ MCQ Exception RuntimeExce Exception does not 0 0
public static void main(String[] args){ occurred ption occurred compile
try{ RuntimeExce
Integer.parseInt("1.0"); ption
}
catch(Exception e){
System.out.println("Exception occurred");
}
catch(RuntimeException ex){
System.out.println("RuntimeException");
}
}}
consider the code above & select the proper
output from the options. 0 1
Which of the following statements are true? MCA Deadlock will The wait() A thread will The notify() Both wait() 0 0.33
(Choose TWO) not occur if method is resume method is and notify()
wait()/notify() overloaded to execution as overloaded to must be called
is used accept a soon as its accept a from a
duration sleep duration duration synchronized
expires. context.
0.33 0 0.33
class s implements Runnable MCQ prints 12 12 DeadLock Cannot Compilation 1 0
{ 12 12 determine Error
int x, y; output.
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? 0 0
Which can appropriately be thrown by a MCQ ClassCastExc NullPointerEx NoClassDefF NumberForm 0 0
programmer using Java SE technology to eption ception oundError atException
create
a desktop application? 0 1
What is the keyword to use when the access of MCQ volatile synchronized final private 0 1
a method has to be restricted to only one
thread at a time 0 0
What will be the output of the program? MCQ hello throwit Compilation hello throwit hello throwit 0 0
caught fails RuntimeExce caught finally
public class RTExcept ption caught after
{ after
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 ");
}
System.out.println("after ");
}
} 0 1
Consider the code below & select the correct MCQ 5 Compilation Compiles but 0 0
ouput from the options: error error at run
public class Test{ time
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));
}} 1 0
Consider the following code and choose the MCQ exit Compiles and Compilation Compiles but 0 0
correct option: no output fails exception at
class Test{ runtime
static void display(){
throw new RuntimeException();
}
public static void main(String args[]){
try{display();
}catch(Exception e){ }
catch(RuntimeException re){}
finally{System.out.println("exit");}}} 1 0
A) Checked Exception must be explicity caught MCQ Only A is Only B is Bothe A and B Both A and B 0 0
or propagated to the calling method TRUE TRUE is TRUE is FALSE
B) If runtime system can not find an
appropriate method to handle the exception,
then the runtime system terminates and uses
the default exception handler. 1 0
public class MyProgram MCQ The program The program The program The program 0 0
{ will not will print Hello will print Hello will print Hello
public static void throwit() compile. world, then world, then world, then
{ will print that a will print that a will print
throw new RuntimeException(); RuntimeExce RuntimeExce Finally
} ption has ption has executing,
public static void main(String args[]) occurred, then occurred, and then will print
{ will print Done then will print that a
try with try block, Finally RuntimeExce
{ and then will executing. ption has
System.out.println("Hello world "); print Finally occurred.
throwit(); executing.
System.out.println("Done with try block
");
}
finally
{
System.out.println("Finally executing ");
}
}
}
which answer most closely indicates the
behavior of the program?
0 1
If a method is capable of causing an exception MCQ true false 1 0
that it does not handle, it must specify this
behavior using throws so that callers of the
method can guard themselves against such
Exception
class Trial{ MCQ Java is We cannot We cannot Nothing is 0 0
public static void main(String[] args){ portable have a try have a try diaplayed
try{ block without block block
System.out.println("Java is portable"); a catch block without a
}}} catch / finally
block 1 0
public static void parse(String str) { MCQ Compilation A A 0 1
try { fails ParseExceptio NumberForm
float f = Float.parseFloat(str); n is thrown by atException is
} catch (NumberFormatException nfe) { the parse thrown by the
f = 0; method at parse method
} finally { runtime. at runtime.
System.out.println(f);
}
}
public static void main(String[] args) {
parse("invalid");
} 0 0
Which digit,and in what order,will be printed MCQ The program The program The program The program The program 0 0
when the following program is run? will only print will only print will only print will only print will only print
5 1 and 4 in 1,2 and 4 in 1 ,4 and 5 in 1,2,4 and 5 in
Public class MyClass { order order order order
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");
}
System.out.println("5");
}
} 0 1 0
Given: MCQ Synchronizing An exception Compilation Declaring the 0 0
public class TestSeven extends Thread { the run() is thrown at fails. doThings()
private static int x; method would runtime. method as
public synchronized void doThings() { make the static would
int current = x; class thread- make the
current++; safe. class thread-
x = current; safe.
}
public void run() {
doThings();
}
}
Which statement is true? 0 1
Which of the following statements is/are true? MCQ Both Statement 2 is Both Statement 1 is 0 0
Statement 1: Writing finally block is optional. Statement 1 & TRUE but Statement 1 & TRUE but
Statement 2: When no exception occurs then Statement 2 Statement 1 is Statement 2 Statement 2 is
complete try block and finally block will execute are FALSE. FALSE. are TRUE. FALSE.
but no catch block will execute.
1 0
Given: MCQ X run = new Thread t = Thread t = Thread t = 1 0
class X implements Runnable X(); Thread t = new new Thread(); new
{ new Thread(X); x.run(); Thread(X);
public static void main(String args[]) Thread(run); t.start();
{ t.start();
/* Some code */
}
public void run() {}
}
Which of the following line of code is suitable to
start a thread ? 0 0
Given: MCQ X, followed by No output, X, followed by none 1 0
class X { public void foo() { System.out.print("X an Exception. and an an Exception,
"); } } Exception is followed by B.
thrown.
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) {
new SubB().foo();
}
}
What is the result? 0 0
Which three of the following are methods of the MCQ 1, 2, 4 2, 4, 5 1, 2, 6 2, 3, 4 0 0
Object class?

1.notify();
2.notifyAll();
3.isInterrupted();
4.synchronized();
5.interrupt();
6.wait(long msecs);
7.sleep(long msecs);
8.yield(); 1 0
public class RTExcept MCQ hello throwit hello throwit hello throwit Compilation 1 0
{ caught finally caught RuntimeExce fails
public static void throwit () after ption caught
{ after
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 ");
}
System.out.println("after ");
}
} 0 0
What will happen when you attempt to compile MCQ A compile A run time Clean compile Clean compile 0 0
and run the following code? time error error and at run but no output
public class Bground extends Thread{ indicating that indicating that time the at runtime
public static void main(String argv[]){ no run method no run method values 0 to 9
Bground b = new Bground(); is defined for is defined for are printed out
b.run(); the Thread the Thread
} class class
public void start(){
for (int i = 0; i <10; i++){
System.out.println("Value of i = "
+ i);
}
}
} 0 1
Given two programs: MCA 567 5 followed by Compilation Compilation Compilation 0 0
1. package pkgA; an exception fails with an fails with an fails with an
2. public class Abc { error on line 7 error on line 8 error on line 9
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. }
12. }
What is the result when the second program is
run? (Choose all that apply) 0 0.5 0.5
What will the output of following code? MCQ finished Exception compilation ArithmeticExc 0 0
fails eption
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
1 0
Given: MCQ Exception A,B,Exception Compilation Compilation 0 0
11. class A { fails because fails because
12. public void process() { of an error in of an error in
System.out.print("A,"); } line 20. line 14.
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("Exception"); }
22. }
What is the result?
0 1
Consider the following code and choose the MCQ reads data Compilation reads data Compiles but 0 1
correct option: from file error from file error at
public class Test { named jlist.lst named jlist.lst runtime
public static void main(String[] args) { in byte form in byte form
File file=new File("D:/jlist.lst"); and display it and display
byte buffer[]=new byte[(int)file.length()+1]; on console. garbage value
FileInputStream fis=new FileInputStream(file);
fis.read(buffer);
System.out.println(buffer);
}
}
0 0
Consider the following code and choose the MCQ reads data Compilation reads data Compiles but 1 0
correct option: from file one error from file error at
public class Test { byte at a time named jlist.lst runtime
public static void main(String[] args) throws and display it in byte form
IOException { on the and display
File file=new File("D:/jlist.lst"); console. garbage value
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
import java.io.EOFException; MCQ The program The program The program The program 0 0
import java.io.FileInputStream; will not will compile will compile will compile,
import java.io.FileNotFoundException; compile and print and print print H|e|l|l|o|,
import java.io.IOException; because a H|e|l|l|o|Input H|e|l|l|o|End of and then
import java.io.InputStreamReader; certain error. stream. terminate
public class MoreEndings { unchecked normally.
public static void main(String[] args) { exception is
try { not caught.
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");
}
}
}
Assume that the file "seq.txt" exists in the
current directory, has the required
access permissions, and contains the string
"Hello".
Which statement about the program is true? 0 1
Consider the following code and choose the MCQ I am a Person I am a Student I am a Person I am a Student 0 1
correct output: I am a Student I am a Person
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();
}
} 0 0
Consider the following code and choose the MCQ Skip the first Compilation Compiles and Compiles but 1 0
correct option: seven error runs without error at
public class Test{ characters output runtime
public static void main(String[] args) throws and then
IOException { starts reading
File file = new File("d:/temp.txt"); file and
FileReader reader=new FileReader(file); display it on
reader.skip(7); int ch; console
while((ch=reader.read())!=-1){
System.out.print((char)ch); } }} 0 0
Consider the following code and choose the MCQ reads data Compilation reads data Compiles but 1 0
correct option: from file error from file error at
public class Test { named jlist.lst named jlist.lst runtime
public static void main(String[] args) throws in byte form in byte form
IOException { and display it and display
File file=new File("D:/jlist.lst"); on console. garbage value
byte buffer[]=new byte[(int)file.length()+1];
FileInputStream fis=new FileInputStream(file);
fis.read(buffer);
System.out.println(new String(buffer)); }}
0 0
Which of these are two legal ways of accessing MCQ A,D B,C C,D A,B 0 0
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");
D)FileReader fr = new FileReader("file.tst",
"UTF8"); 0 1
Consider the following code and choose the MCQ the state of Compilation Compiles but the state of 0 0
correct option: the object s1 error error at run the object s1
class std{ will be store to time will not be
int call; std(int c){call=c;} file std.txt store to the
int getCall(){return call;} file.
}
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();
}} 1 0
Consider the following code and choose the MCQ reads data Compilation reads data Compiles but 0 0
correct option: from file one error from file error at
public class Test { byte at a time named jlist.lst runtime
public static void main(String[] args) throws and display it in byte form
IOException { on the and ascii
File file=new File("D:/jlist.lst"); console. value
byte buffer[]=new byte[(int)file.length()+1];
FileInputStream fis=new FileInputStream(file);
int ch=0;
while((ch=fis.read())!=-1){
System.out.print(ch); } }}
1 0
What happens when the constructor for MCQ throws a throws a throws a returns null 0 1
FileInputStream fails to open a file for reading? DataFormatEx FileNotFound ArrayIndexOut
ception Exception OfBoundsExc
eption 0 0
import java.io.*; MCQ Compilation An exception An instance of A instance of 1 0
public class MyClass implements Serializable { fails is thrown at MyClass is MyClass and
runtime serialized an instance of
private Tree tree = new Tree(); Tree are both
serialized
public static void main(String [] args) {
MyClass mc= new MyClass();
try {
FileOutputStream fs = new
FileOutputStream(”MyClass.ser”);
ObjectOutputStream os = new
ObjectOutputStream(fs);
os.writeObject(mc); os.close();
} catch (Exception ex) { ex.printStackTrace(); }
}}

0 0
What is the DataOutputStream method that MCQ writeBytes() writeFloat() write() writeDouble() 0 0
writes double precision floating point values to
a stream? 0 1
Which of the following opens the file MCQ FileOutputStre FileOutputStre DataOutputStr FileOutputStre 0 1
"myData.stuff" for output first deleting any file am fos = new am fos = new eam dos = am fos = new
with that name? FileOutputStre FileOutputStre new FileOutputStre
am( am( DataOutputStr am( new
"myData.stuff" "myData.stuff" eam( BufferedOutp
, true ) ) "myData.stuff" utStream(
) "myData.stuff"
))
0 0
A file is readable but not writable on the file MCQ A The boolean The boolean
The file is none of the 0 1
system of the host platform. What will SecurityExcep value false is value true is
modified from listed options
be the result of calling the method canWrite() tion is thrown returned returned
being
on a File object representing this file? unwritable to
being
writable. 0 0 0
Consider the following code and choose the MCQ The file The file The file The file Compilation 0 0
correct option: system has a system has a system has a system has a error
public class Test{ new empty new empty directory directory
public static void main(String[] args) { directory directory named dir, named
File dir = new File("dir"); named dir named containing a newDir,
dir.mkdir(); newDir file f1.txt containing a
File f1 = new File(dir, "f1.txt"); try { file f1.txt
f1.createNewFile(); } catch (IOException e) { ;
}
File newDir = new File("newDir");
dir.renameTo(newDir);} } 0 1 0
Consider the following code and choose the MCQ writes data to Compilation writes data to Compiles but 1 0
correct option: file in byte error the file in error at
public class Test { form. character runtime
public static void main(String[] args) throws form.
IOException {
String data="Confidential info";
byte buffer[]=data.getBytes();
FileOutputStream fos=new
FileOutputStream("d:/temp");
for(byte d : buffer){
fos.write(d); } }} 0 0
Consider the following code and choose the MCQ creates Compilation Compiles but Compiles and 0 0
correct option: directories error error at run executes but
public class Test { names prj and time directories are
public static void main(String[] args) { lib in d: drive not created
File file=new File("d:/prj,d:/lib");
file.mkdirs();}} 0 1
Consider the following code and choose the MCQ Transfer Compilation Compiles and Compiles but 0 0
correct option: content of file error runs but error at
public class Test { data to the content not runtime
public static void main(String[] args) throws temp.txt transferred to
IOException { the temp.txt
File file=new File("d:/data");
byte buffer[]=new byte[(int)file.length()+1];
FileInputStream fis=new FileInputStream(file);
fis.read(buffer);
FileWriter fw=new FileWriter("d:/temp.txt");
fw.write(new String(buffer));}}
1 0
Consider the following code and choose the MCQ the state of Compilation Compiles but the state of 1 0
correct option: the object s1 error error at run the object s1
class std implements Serializable{ will be store to time will not be
int call; std(int c){call=c;} file std.txt store to the
int getCall(){return call;} file.
}
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();
}} 0 0
Given : MCQ ab abcd ab cd abcd Compilation 0 0
import java.io.*; Error
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
cd
What is the result? 0 0 1
Consider the following code and choose the MCQ creates Compilation Compiles but Compiles and 1 0
correct option: directory error error at run executes but
public class Test { d:/prj/lib time directory is not
public static void main(String[] args) { created
File file=new File("d:/prj/lib");
file.mkdirs();}} 0 0
import java.io.*; MCQ s.writeInt(x); s.serialize(x); s.defaultWrite s.writeObject( 0 0
public class MyClass implements Serializable { Object(); x);
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


allow Foo objects to be
correctly serialized and deserialized?
1 0
A) It is not possible to execute select query with MCQ Both A and B Only A is Only B is Both A and B 1 0
execute() method is FALSE TRUE TRUE is TRUE
B) CallableStatement can executes store
procedures only but not functions 0 0
A) When one use callablestatement, in that MCQ Both A and B Only A is Only B is Both A and B 0 0
case only parameters are send over network is FALSE TRUE TRUE is TRUE
not sql query.
B) In preparestatement sql query will compile
for first time only 0 1
getConnection() is method available in? MCQ DriverManage Driver ResultSet Statement PreparedState 1 0
r Class Interface Interface Interface ment Interface
0 0 0
Sylvy wants to develop Student management MCQ Statement CallableState PreparedState RowSet 0 0
system, which requires frequent insert ment ment
operation about student details. In order to
insert student record which statement interface
will give good performance 1 0
Which method will return boolean when we try MCQ executeUpdat executeSQL() execute() executeQuery 0 0
to execute SQL Query from a JDBC program? e() ()
1 0
An application can connect to different MCQ true false 1 0
Databases at the same time. State
TRUE/FALSE.
A) By default, all JDBC transactions are auto MCQ Only A and B Only B and C Both A and C All are TRUE 0 0
commit is TRUE is True is TRUE
B) PreparedStatement suitable for dynamic sql
and requires one time compilation
C) with JDBC it is possible to fetch information
about the database 0 1
how to register driver class in the memory? MCQ Using Using the Either None of the 0 0
forName() static method forName() or given options
which is a registerDriver( registerDriver(
static method ) method )
which is
available in
DriverManage
r Class. 1 0
What is the use of wasNull() in ResultSet MCQ There is no It returns true It returns int none of the 0 1
interface? such method when last value as listed options
in ResultSet read column mentioned
interface contain SQL below: > 0 if
NULL else many columns
returns false Contain Null
Value < 0 if no
column
contains Null
Value = 0 if
one column
contains Null
value
0 0
Which of the following options contains only MCQ 1) Driver 2) 1) Driver 2) 1) Driver 2) All of the 0 0
JDBC interfaces? Connection 3) Connection 3) Connection 3) given options
ResultSet 4) ResultSet 4) ResultSet 4)
DriverManage ResultSetMet ResultSetMet
r 5) Class aData 5) aData 5)
Statement 6) Statement 6)
DriverManage PreparedState
r 7) ment 7)
PreparedState Callablestate
ment 8) ment 8)
Callablestate DataBaseMet
ment 9) aData
DataBaseMet
aData 1 0
class CreateFile{ MCA Line 16 is An exception Line 13 Line 13 0 0.5
public static void main(String[] args) { never is thrown at creates a File creates a
try { executed runtime object named directory
File directory = new File("c"); //Line 13 “c” named “c” in
File file = new File(directory,"myFile"); the file
if(!file.exists()) { system.
file.createNewFile(); //Line 16
}}
catch(IOException e) {
e.printStackTrace }
}}}
If the current direcory does not consists of
directory "c", Which statements are true ?
(Choose TWO) 0.5 0
By default all JDBC transactions are MCQ true false 1 0
autocommit. State TRUE/FALSE.
Give Code snipet: MCQ java.sql.Resul java.sql.Driver java.sql.Driver java.sql.Conn 1 0
{// Somecode tSet Manager ection
ResultSet rs = st.executeQuery("SELECT *
FROM survey");

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

rs.close();
// somecode
} What should be imported related to
ResultSet? 0 0
Consider the following code & select the MCQ will show first Compilation Compiles but Compiles but 0 0
correct option for output. employee error error at run no output
String sql ="select empno,ename from emp"; record time
PreparedStatement
pst=cn.prepareStatement(sql);
System.out.println(pst.toString());
ResultSet rs=pst.executeQuery();
System.out.println(rs.getString(1)+ "
"+rs.getString(2));
1 0
What is the default type of ResultSet in JDBC MCQ Read Only, Updatable, Read only, Updatable, 1 0
applications? Forward Only Forward only Scroll Scroll
Sensitive sensitive 0 0
Consider the code below & select the correct MCQ will show all Compilation Compiles but Compiles but 0 0
ouput from the options: row of first error error at run run without
column time output
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)); } 1 0
Cosider the following code & select the correct MCQ will show only Compilation will show city Compiles but 0 0
output. name error error at run
String sql ="select rollno, name from student"; time
PreparedStatement
pst=cn.prepareStatement(sql);
System.out.println(pst.toString());
ResultSet rs=pst.executeQuery();
while(rs.next()){
System.out.println(rs.getString(3)); }
0 1
Given : MCQ java.sql.Driver java.sql.Driver java.sql.Driver java.sql.DataS 0 0
public class MoreEndings { java.sql.Driver ource
public static void main(String[] args) throws Manager
Exception {
Class driverClass =
Class.forName("sun.jdbc.odbc.JdbcOdbcDrive
r");
DriverManager.registerDriver((Driver)
driverClass.newInstance());
// Some code
} Inorder to compile & execute this code, what
should we import? 1 0
Which of the following methods finds the MCQ Database.get Connection.ge DatabaseMet ResultSetMet 0 0
maximum number of connections that a MaxConnectio tMaxConnecti aData.getMax aData.getMax
specific driver can obtain? ns ons Connections Connections 1 0
Which of the following method can be used to MCQ executeAll() executeAllSQ execute() executeQuery executeUpdat 0 0
execute to execute all type of queries i.e. either L() () e()
Selection or Updation SQL Queries? 1 0 0
It is possible to insert/update record in a table MCQ true false 1 0
by using ResultSet. State TRUE/FALSE

Which of the following methods are needed for MCQ registerDriver( Class.forNam registerDriver( getConnection 0 0
loading a database driver in JDBC? ) method e() ) method and
Class.forNam
e() 1 0
Carefully read the question and answer MCQ specifier Inheritance Implementatio Access Class 0 0
accordingly. n specifier
________ determines which member of a class
can be used by other classes. 0 1 0
Carefully read the question and answer MCQ protected final,interface public,friend final,protected private,abstra 0 1
accordingly. ,interface ct
A class can be declared as _______ if you do
not want the class to be subclassed. Using
the __________keyword we can abstract a
class from its implementation
0 0 0
Carefully read the question and answer MCQ super class display display super class 0 1
accordingly. method method method method
What will be the output for following code? display display display display
class Super method 20 20 method 10 10 method 20 20 method 10 10
{
int num=20;
public void display()
{
System.out.println("super class method");
}
}
public class ThisUse extends Super
{
int num;
public ThisUse(int num)
{
this.num=num;
}
public void display()
{
System.out.println("display method");
}
public void Show()
{
this.display();
display();
System.out.println(this.num);
System.out.println(num);
}
public static void main(String[]args)
{
ThisUse o=new ThisUse(10); 0 0
o.Show();read the question and answer
Carefully MCQ 10 11 Compilation None of the 0 0
accordingly. error listed options
What will be the output for following code?
public class Variables
{
public static void main(String[]args)
{
public int i=10;
System.out.println(i++);
}
} 1 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
The constructor of a class must not have a
return type.
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
When one method is overridden in sub class
the access specifier of the method in sub class
should be equal as method in super class.
State True or False.

Carefully read the question and answer MCQ Class Public Constructor Destructor Variable 0 0
accordingly.
Which of the following method is used to
initialize the instance variable of a class. 1 0 0
Carefully read the question and answer MCQ protected or protected or None of the private 0 1
accordingly. default public listed options
If display method in super class has a
protected specifier then what should be the
specifier for the overriding display method in
sub class? 0 0
Carefully read the question and answer MCQ super class super class sub class Compilation 1 0
accordingly. show method show method show method Error
What will be the output for following code? sub class super class
class Super show method show method
{
static void show()
{
System.out.println("super class show
method");
}
static class StaticMethods
{
void show()
{
System.out.println("sub class show method");
}
}
public static void main(String[]args)
{
Super.show();
new Super.StaticMethods().show();
}
}
0 0
Carefully read the question and answer MCQ I II & IV III I & III 1 0
accordingly.
Which of the following statements are true
about Method Overriding?
I: Signature must be same including return
type
II: If the super class method is throwing the
exception then overriding method should throw
the same Exception
III: Overriding can be done in same class
IV: Overriding should be done in two different
classes with no relation between the classes 0 0
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
A field with default access specifier can be
accessed out side the package.
State True or False.
Carefully read the question and answer MCQ If one class is A class can All members Protected is 1 0
accordingly. having be declared of abstract default access
Which of the following are true about protected protected as protected. class are by modifier of a
access specifier? method then default child class
the method is protected
available for
subclass
which is
present in
another
package 0 0
Carefully read the question and answer MCQ super class super class Compilation None of the 1 0
accordingly. exe method exe method error listed options
What will be the output of following code? sub class super class
class Super2 display display
{ method method
public void display()
{
System.out.println("super class display
method");
}
public void exe()
{
System.out.println("super class exe method");
display();
}
}
public class InheritMethod extends Super2
{
public void display()
{

System.out.println("sub class display method");


}

public static void main(String [] args)


{

InheritMethod o=new InheritMethod();

o.exe();
}
0 0
}
Carefully read the question and answer MCQ Constructors Constructors Constructor is Constructors 1 0
accordingly. can be can be a special type should be
Which of the following are true about overloaded overridden. of method called
constructors? which may explicitly like
have return methods
type. 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Constructor of an class is executed each time
when an object of that class is created
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
The below code will compile & provide
desired output:
package p1;
class Parent {
private int doWork(){
System.out.println("Do Work - Parent");
return 0;
}
}
class Child extends Parent {
public void doWork(){
System.out.println("Do Work - Child");
}
}
class Test{
public static void main(String[] args) {
new Child().doWork();
}
}
Carefully read the question and answer MCQ 1&2 1&2&3 2&3 1&2&4 2&4 0 0
accordingly.
public interface Status
{
/* insert code here */ int MY_VALUE = 10;
}
Which are valid on commented line?
1.final
2.static
3.native
4.public 0 1 0
Carefully read the question and answer MCQ Child Parent Parent Child Parent Child 0 0
accordingly.
What is the outputof below code:
package p1;
class Parent {
public static void doWork() {
System.out.println("Parent");
}
}
class Child extends Parent {
public static void doWork() {
System.out.println("Child");
}
}
class Test {
public static void main(String[] args) {
Child.doWork();
}
} 1 0
Carefully read the question and answer MCQ 1&2 1&3 2&3 3&4 2&4 0 0
accordingly.
abstract public class Employee
{
protected abstract double getSalesAmount();
public double getCommision() {
return getSalesAmount() * 0.15;
}
}
class Sales extends Employee
{
// insert method here
}
Which two methods, inserted independently,
correctly complete the Sales
class?
1.double getSalesAmount() { return 1230.45; }
2. public double getSalesAmount() { return
1230.45; }
3.private double getSalesAmount() { return
1230.45; }
4.protected double getSalesAmount() { return
1230.45; }

0 0 1
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
Object class provides a method named
getClass() which returns runtime class of an
object.
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
State whether TRUE or FALSE.
A concrete class can extend more than one
super class whether that super class is either
concrete or abstract class
Carefully read the question and answer MCQ final protected static abstract 1 0
accordingly.
Which of the following keywords ensures that a
method cannot be overridden? 0 0
Carefully read the question and answer MCQ Class cannot Runtime WD 500 Compile 0 0
accordingly. be defined Error. Error.
public class Client1 inside another
{ class
public static void main(String [] args)
{
PenDrive p;
PenDrive.Vendor v1=new
PenDrive.Vendor("WD",500);
System.out.println(v1.getName());
System.out.println(v1.getPrice());
}
}
class PenDrive
{
static class Vendor
{
String name;
int price;
public String getName(){ return name;}
public int getPrice(){ return price;}

Vendor(String name,int price)


{
this.name=name;
this.price=price;
}
}
}
What will be the output of the given code? 1 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
The below code will compile & provide
desired output:
package p1;
abstract class LivingThings{
public abstract void resperate();
interface Living
{
public abstract void walk();
}
}
class Human implements LivingThings.Living{
@Override
public void walk() {
System.out.println("Human Can Walk");
}
}
class Test {
public static void main(String[] args) {
new Human().walk();
}
}
Carefully read the question and answer MCQ 10 50 20 50 20 10 10 20 0 1
accordingly.
What will be the output for following code?
class super3{
int i=10;
public super3(int num){
i=num;
}
}
public class Inherite1 extends super3{
public Inherite1(int a){
super(a);
}
public void Exe(){
System.out.println(i);
}
public static void main(String[]args){
Inherite1 o=new Inherite1(50);
super3 s=new Inherite1(20);
System.out.println(s.i);
o.Exe();
}
} 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
An overriding method can also return a subtype
of the type returned by the overridden method.

Carefully read the question and answer MCQ TRUE FALSE 0 1


accordingly.
State whether TRUE or FALSE.
An abstract class cannot contain non abstract
methods
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
The super() call can only be used in constructor
calls and not method calls.
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
State whether TRUE or FALSE.
The below code will compile & provide
desired output:
package p1;
interface A {
public abstract void methodOne();
}
interface B extends A {
public abstract void methodTwo();
}
class C implements B{
@Override
public void methodTwo() {
System.out.println("Method Two Body");
}
}
class Test {
public static void main(String[] args) {
new C().methodTwo();
}
}
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
If any class has at least one abstract method
you must declare it as abstract class

Carefully read the question and answer MCQ TRUE FALSE 0 1


accordingly.
State whether TRUE or FALSE.
If any method overrides one of it’s super class
methods, we can invoke the overridden method
through the this keyword.
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
State whether TRUE or FALSE.
The below code will compile & provide
desired output:
package p1;
interface Bounceable {
void bounce();
void setBounceFactor(int bf);
private class BusinessLogic
{
int var1;
float var2;
double result(int var1,float var2){
return var1*var2;
}
}
}
class Test {
public static void main(String[] args) {
System.out.println(new
Bounceable.BusinessLogic().result(12,12345.2
2F));
}
}
Carefully read the question and answer MCQ public void public void public void All of the 0 0
accordingly. aM2(){} aM1(){} bM2(){} listed options
interface B
{
public void bM1();
public void bM2();
}
abstract class A implements B
{
public abstract void aM1();
public abstract void aM2();
public void bM1(){}
}
public class Demo extends A
{
}
In above scenario class Demo must override
which methods? 0 1
Carefully read the question and answer MCQ public void public void public void public void 0 0
accordingly. aM1(){} public bM1(){} public aM1(){} public aM1(){} public
interface A void aM2(){} void bM2(){} void aM2(){} void bM2(){}
{ public void
public abstract void aM1(); bM1(){} public
public abstract void aM2(); void bM2(){}
}
interface B extends A
{
public void bM1();
public void bM2();
}
public class Demo extends Object implements
B
{
}
In above scenario class Demo must override
which methods? 1 0
Carefully read the question and answer MCQ they're not t1's an Object they're not No Output 0 0
accordingly. equal equal t1's an Will be
What is the output of below code: Object Displayed
package p1;
public class Test {
public static void main(String[] args) {
Test t1 = new Test();
Test t2 = new Test();
if (!t1.equals(t2))
System.out.println("they're not equal");
if (t1 instanceof Object)
System.out.println("t1's an Object");
}
} 1 0
Carefully read the question and answer MCQ Statement I & Statement I is Statement I is Statement I & 1 0
accordingly. II are TRUE TRUE & II is FALSE & II is II are FASLE
Choose the correct option. FALSE TRUE
Statement I: When an abstract class is sub
classed, the subclass should provide the
implementation for all the abstract methods in
its parent class.
Statement II: If the subclass does not
implement the abstract method in its parent
class, then the subclass must also be declared
abstract. 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
Interface can be used when common
functionalities have to be implemented
differently across multiple classes.
Carefully read the question and answer MCQ Statement I & Statement I is Statement I is Statement I & 1 0
accordingly. II are TRUE TRUE & II is FALSE & II is II are FASLE
Choose the correct option. FALSE TRUE
Statement I: When all methods in a class are
abstract the class can be declared as an
interface.
Choose the correct option.
Statement II: An interface defines a contract for
classes to implement the behavior. 0 0
Carefully read the question and answer MCQ Human Can Compilation Runtime No Output will 0 1
accordingly. Walk Error Exception be displayed
What is the outputof below code:
package p1;
abstract class LivingThings{
public abstract int walk();
}
class Human extends LivingThings{
@Override
public void walk() {
System.out.println("Human Can Walk");
}
}
class Test {
public static void main(String[] args) {
new Human().walk();
}
} 0 0
Carefully read the question and answer MCQ 0, 0, 0 120, 60, 0 60,60,60 120, 120, 120 0 0
accordingly.
abstract class Vehicle
{
public int speed()
{
return 0;
}
}
class Car extends Vehicle
{
public int speed()
{
return 60;
}
}
class RaceCar extends Car
{
public int speed()
{
return 120;
}
}
public class Demo
{
public static void main(String [] args)
{
RaceCar racer = new RaceCar();
Car car = new RaceCar();
Vehicle vehicle = new RaceCar();
System.out.println(racer.speed() + ", " +
car.speed()+", " + vehicle.speed()); 0 1
}
Carefully read the question and answer MCQ DigiCam do Compilation DigiCam do Runtime Error 1 0
accordingly. Charge You Error Charge
What will be the output of following code? are Sending:
class InterfaceDemo MyFamily.jpg
{
public static void main(String [] args)
{
new DigiCam(){}.doCharge();
new DigiCam(){
public void writeData (String msg)
{
System.out.println("You are Sending: "+msg);
}
}.writeData("MyFamily.jpg");
}//main
}
interface USB
{
int readData();
void writeData(String input);
void doCharge();
}
abstract class DigiCam implements USB
{
public int readData(){ return 0;}
public void writeData(String input){}
public void doCharge()
{
System.out.println("DigiCam do Charge");
}
}
0 0
Carefully read the question and answer MCQ The equals Compilation This class The code will 1 0
accordingly. method does fails because must also compile as
public class Person NOT properly the private implement the Object class's
{ override the attribute hashCode equals
private String name; Object class's p.name method as method is
public Person(String name) { this.name = equals cannot be well. overridden.
name; } method. accessed.
public boolean equals(Person p)
{
return p.name.equals(this.name);
}
}
Which statement is true? 0 0
Carefully read the question and answer MCQ Statement I & Statement I is Statement I is Statement I & 1 0
accordingly. II are TRUE TRUE & II is FALSE & II is II are FASLE
Abstract classes can be used when FALSE TRUE
Statement I: Some implemented functionalities
are common between classes
Statement II: Some functionalities need to be
implemented in sub classes that extends the
abstract class 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
The below code will compile & provide
desired output:
package p1;
interface A {
public abstract void methodOne();
}
interface B{
public abstract void methodTwo();
}
interface C{
public abstract void methodTwo();
}
class D implements B,C,A{
public void methodOne(){}
public void methodTwo(){
System.out.println("Method Two");}
}
class Test {
public static void main(String[] args) {
new D().methodTwo();
}
}
Carefully read the question and answer MCQ Aggregation Composition Generic Polymorphic 1 0
accordingly.
Which of the following correctly fits for the
definition 'holding instances of other objects'?
0 0
Carefully read the question and answer MCQ It will print It will give It will print 5 None of the 0 1
accordingly. ArithmeticExc ArithmeticExc listed options
What will be the output for following code eption and eption
public class prints 5
MethodOverloading {
int m=10,n;
public void div(int a) throws Exception{
n=m/a;
System.out.println(n);
}
public void div(int a,int b) {
n=a/b;
}
public static void main(String[]args) throws
Exception{
MethodOverloading o=new
MethodOverloading();
o.div(0);
o.div(10,2);
}
} 0 0
Carefully read the question and answer MCQ Code will not Code will Code will Runtime 1 0
accordingly. compile due Compile compile but Exception
class InterfaceDemo to weaker without any wont print any
{ access Error message
public static void main(String [] args) privilege.
{
DigiCam cam1=new DigiCam();
cam1.doCharge();
}//main
}
interface USB
{
int readData();
boolean writeData(String input);
void doCharge();
}
class DigiCam implements USB
{
public int readData(){ return 0;}
public boolean writeData(String input){ return
false; }
void doCharge(){ return;}
}
Which of the following is correct with respect to
given code? 0 0
Carefully read the question and answer MCQ Statement I & Statement I is Statement I is Statement I & 1 0
accordingly. II are TRUE TRUE & II is FALSE & II is II are FASLE
Choose the correct option. FALSE TRUE
Statement I: A subclass inherits all of the
“public” and “protected” members of its parent,
no matter what package the subclass is in.
Statement II: If the subclass of any class is in
the same package then it inherits the default
access members of the parent.
0 0
Carefully read the question and answer MCQ 1&2 1&3 2&3 3&4 2&4 0 0
accordingly.
public abstract class Shape
{
private int x;
private int y;
public abstract void draw();
public void setAnchor(int x, int y)
{
this.x = x;
this.y = y;
}
}
Which two classes use the Shape class
correctly?
1.public class Circle implements Shape {
private int radius;
}
2.public abstract class Circle extends Shape {
private int radius;
}
3.public class Circle extends Shape {
private int radius;
public void draw();
}
4.public class Circle extends Shape {
private int radius;
public void draw() {/* code here */}
}
0 0 1
Carefully read the question and answer MCQ System.free(); System.setGa System.out.gc System.gc(); 0 0
accordingly. rbageCollectio ();
Which of the following is the correct syntax for n();
suggesting that the JVM to performs garbage
collection? 0 1
Carefully read the question and answer MCQ Both Statement A Statement B Neither 1 0
accordingly. Statements A alone alone Statements A
Which of the following code snippets make and B nor B
objects eligible for Garbage Collection?
Statement A: String s = "new string"; s =
s.replace('e', '3');
Statement B:String replaceable =
"replaceable"; StringBuffer sb = new
StringBuffer(replaceable);replaceable = null; sb
= null; 0 0
Carefully read the question and answer MCQ line 3 line 4 line 5 line 1 0 1
accordingly.
After which line the object initially referred by
str ("Hello" String object) is eligible for garbage
collection?
class Garbage{
public static void main(string[]args){
line 1:String str=new String("Hello");
line 2. String str1=str;
line 3.str=new String("Hi");
line 4.str1=new String("Hello Again");
5.return;
}
} 0 0
Carefully read the question and answer MCQ Both Statement A Statement A Both 1 0
accordingly. Statements A is true and is false and Statements A
Statement A:finalize will always run before an and B are true Statement B Statement B and B are
object is garbage collected is false is true false
Statement B:finalize method will be called only
once by the garbage collector
which of the following is true? 0 0
Carefully read the question and answer MCQ Option 2 Option 3 Option 1 Option 4 0 0
accordingly.
How can you force garbage collection of an
object?
1.Garbage collection cannot be forced
2.Call System.gc().
3.Call Runtime.gc().
4. Set all references to the object to new
values(null, for example). 1 0
Carefully read the question and answer MCQ address dot scope none of these 0 1
accordingly. resolution
Members of the classs are accessed by
_________ operator 0 0
Carefully read the question and answer MCQ 97 a compilation None of the 0 0
accordingly. error listed options
What will be the output for following code?
public class VariableDec1
{
public static void main(String[]args)
{
int I=32;
char c=65;
char a=c+I;
System.out.println(a);
}
} 1 0
Carefully read the question and answer MCQ 1 3 4 2 0 0
accordingly.
What will be the output for following code?
public class Variabledec {
public static void main(String[]args){
boolean x = true;
int a;
if(x) a = x ? 2: 1;
else a = x ? 3: 4;
System.out.println(a);
}
} 0 1
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Garbage collector thread is a daemon thread.
State True or False.

Carefully read the question and answer MCA try catch finally access exception 0 0
accordingly.
Find the keyword which is not used to
implement exception 0 0.5 0.5
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
The ++ operator postfix and prefix has the
same effect
Carefully read the question and answer MCQ 102 34 4 Compilation 0 1
accordingly. error
What will be the output for following code?
public class VariableDec
{
public static void main(String[]args)
{
int x = 1;
if(x>0 )
x = 3;
switch(x)
{
case 1: System.out.println(1);
case 0: System.out.println(0);
case 2: System.out.println(2);
break;
case 3: System.out.println(3);
default: System.out.println(4);
break;
}
}
} 0 0
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
Garbage collection guarantee that a program
will not run out of memory. State True or False.

Carefully read the question and answer MCQ 12,12,-1 13,12,0 13,13,0 12,13,-1 0 1
accordingly.
What will be the output for following code?
public class Operators
{
public static void main(String[]args)
{
int i=12;
int j=13;
int k=++i-j--;
System.out.println(i);
System.out.println(j);
System.out.println(k);
}
} 0 0
Carefully read the question and answer MCQ extends implements throwed Integer Boolean 0 0
accordingly.
Which of the following is not the Java
keyword? 1 0 0
Carefully read the question and answer MCQ class new print main Object 0 1
accordingly.
_____________ Operator is used to create an
object. 0 0 0
Carefully read the question and answer MCQ III->I->II->IV. I->III->II->IV I->III->IV->II I->II->III->IV 1 0
accordingly.
What is the correct structure of a java
program?
I: import statement
II: class declaration
III: package statement
IV: method,variable declarations 0 0
Carefully read the question and answer MCQ An exception The code The code Compilation 1 0
accordingly. is thrown at executes executes fails.
public class Threads runtime. normally and normally, but
{ prints "Run". nothing is
public static void main (String[] args) printed.
{
new Threads().go();
}
public void go()
{
Runnable r = new Runnable()
{
public void run()
{
System.out.print("Run");
}
};

Thread t = new Thread(r);


t.start();
t.start();
}
}
What will be the result? 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
Threads are small process which run in shared
memory space within a process.
Carefully read the question and answer MCQ Compile Error Important job String in run Important job No Output 0 0
accordingly. running in running in
Predict the output of below code: MyThread MyThread
package p1; String in run
class MyThread extends Thread {
public void run(int a) {
System.out.println("Important job running in
MyThread");
}
public void run(String s) {
System.out.println("String in run");
}
}
class Test {
public static void main(String[] args) {
MyThread t1=new MyThread();
t1.start();
}
} 0 0 1
Carefully read the question and answer MCQ Compile Error Important job Runtime Non of the 0 1
accordingly. running in Exception options
What will be the output of below code: MyThread
package p1;
class MyThread extends Thread {
public void run() {
System.out.println("Important job running in
MyThread");
}
}
class Test {
public static void main(String[] args) {
MyThread t1=new MyThread();
t1.run();
}
} 0 0
Carefully read the question and answer MCQ It will compile It will compile The code will Compilation 0 0
accordingly. and the run and calling cause an error will cause an
class Background implements Runnable{ method will start will print at compile error because
int i = 0; print out the out the time. while cannot
public int run(){ increasing increasing take a
while (true) { value of i. value of i. parameter of
i++; true.
System.out.println("i="+i);
}
return 1;
}
}//End class 1 0
Carefully read the question and answer MCQ Statement1 is Statement2 is BOTH BOTH 0 1
accordingly. TRUE but TRUE but Statement1 & Statement1 &
Which of the following statements are true? Statement2 is Statement1 is Statement2 Statement2
Statement1: When a thread is sleeping as a FALSE. FALSE. are TRUE. are FALSE.
result of sleep(), it releases its locks.
Statement2: The Object.wait() method can be
invoked only from a synchronized context.
0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
The below code will compile & provide
desired output:
package p1;
class MyThread extends Thread {
public void run() {
System.out.println("Important job running in
MyThread");
}
public void run(String s) {
System.out.println("String in run is " + s);
}
}
class Test {
public static void main(String[] args) {
MyThread t1=new MyThread();
t1.start();
}
}
Carefully read the question and answer MCQ You cannot An exception The code The code 0 0
accordingly. call run() is thrown at executes and executes and
public class TestDemo implements Runnable method using runtime. prints prints
{ Thread class "Runner". "RunnerRunn
public void run() object. erRunner".
{
System.out.print("Runner");
}
public static void main(String[] args)
{
Thread t = new Thread(new TestDemo());
t.run();
t.run();
t.start();
}
}
What will be the result?
0 1
Carefully read the question and answer MCQ Exactly 10 Exactly 10 The delay If “Time’s 0 0
accordingly. seconds after seconds after between Over!” is
You have created a TimeOut class as an the start the “Start!” is “Start!” being printed, you
extension of Thread, the purpose of which is to method is printed, printed and can be sure
print a “Time’s Over” message if the Thread is called, “Time’s “Time’s Over!” “Time’s Over!” that at least
not interrupted within 10 seconds of being Over!” will be will be printed. will be 10 10 seconds
started. Here is the run method that you have printed. seconds plus have elapsed
coded: or minus one since “Start!”
public void run() { tick of the was printed.
System.out.println(“Start!”); system clock.
try {
Thread.sleep(10000);
System.out.println(“Time’s Over!”);
} catch (InterruptedException e) {
System.out.println(“Interrupted!”);
}
}Given that a program creates and starts a
TimeOut object, which of the following
statements is true? 0 1
Carefully read the question and answer MCQ Runnable Running Dead Blocked Stop 0 0
accordingly.
Which of the below is invalid state of thread? 0 0 1
Carefully read the question and answer MCQ 1&2 1&3 2&3 1&4 2&4 0 0
accordingly.
Which two statements are true?
1.It is possible for more than two threads to
deadlock at once.
2.The JVM implementation guarantees that
multiple threads cannot enter into a
deadlocked state.
3.Deadlocked threads release once their
sleep() method's sleep duration has expired.
4.If a piece of code is capable of deadlocking,
you cannot eliminate the possibility of
deadlocking by inserting
invocations of Thread.yield().
0 1 0
Carefully read the question and answer MCQ void run() void start() boolean boolean 0 0
accordingly. getPriority() isAlive()
Which of these is not valid method in Thread
class 1 0
Carefully read the question and answer MCQ One Two Three Four 0 1
accordingly.
Java provides ____ ways to create Threads. 0 0
Carefully read the question and answer MCQ wait() notify() notifyAll() all the options 0 0
accordingly.
Inter thread communication is achieved using
which of the below methods? 0 1
Carefully read the question and answer MCA Synchronized Synchronized Synchronized Synchronized Synchronized 0.5 0.5
accordingly. blocks methods classes abstract interfaces
Synchronization is achieved by using which of classes
the below methods 0 0 0
Carefully read the question and answer MCQ Reduce Support Increase Requires less None of the 0 0
accordingly. response time parallel system overheads options.
Which of these is not a benefit of of process. operation of efficiency. compared to
Multithreading? functions. multitasking. 0 0 1
Carefully read the question and answer MCQ [10,abc] [10] Compilation [abc] 0 1
accordingly. error
What will be the output for following code?
public class collection1{
public static void main(String[]args){
Collection c=new ArrayList();
c.add(10);
c.add("abc");
Collection l=new HashSet();
l.add(20);
l.add("abc");
l.add(30);
c.addAll(l);
c.removeAll(l);
System.out.println( c );
}
} 0 0
Carefully read the question and answer MCQ 1&2 1&3 2&3 1&4 2&4 0 0
accordingly.
Which of the following are not List
implementations?
1.Vector
2.Hashtable
3.LinkedList
4.Properties 0 0 1
Carefully read the question and answer MCA List Set SortedList SortedQueue 0.5 0.5
accordingly.
Which of these interface(s) are part of Java’s
core collection framework? 0 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
foreach loop is the only option to iterate over a
Map
Carefully read the question and answer MCQ Prints the Compilation Throws Prints the 0 0
accordingly. output [Green error at line no Runtime output [Green
Consider the following code: World, 1, 8 Exception World, Green
01 import java.util.Set; Green Peace] Peace] at line
02 import java.util.TreeSet; at line no 9 no 9
03
04 class TestSet {
05 public static void main(String[] args) {
06 Set set = new TreeSet<String>();
07 set.add("Green World");
08 set.add(1);
09 set.add("Green Peace");
10 System.out.println(set);
11 }
12 }
Which of the following option gives the output
for the above code? 1 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
LinkedList represents a collection that does not
allow duplicate elements.
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Under java.util package we have "Collections"
as Class and "Collection" as Interface

Carefully read the question and answer MCQ boolean void Object String 0 0
accordingly.
What is the return type of next() in Iterator? 1 0
Carefully read the question and answer MCQ Creates a Creates a Creates a Creates a 0 0
accordingly. Date object Date object Date object Date object
Consider the following partial code: with 0 as with '01-01- with current with current
java.util.Date date = new java.util.Date(); default value 1970 12:00:00 date and time date alone as
Which of the following statement is true AM' as default as default default value
regarding the above partial code? value value
1 0
Carefully read the question and answer MCA The Iterator The The The 0.33 0
accordingly. interface ListIterator ListIterator ListIterator
Which of the following are true statements? declares only interface interface interface
three extends both provides the provides
methods: the List and ability to forward and
hasNext, next Iterator determine its backward
and remove. interfaces position in the iteration
List. capabilities. 0.33 0.33
Carefully read the question and answer MCQ int String Object set1 0 0
accordingly.
What is the data type of m in the following
code?
import java.util.*;
public class set1
{
public static void main(String [] args)
{
Set s=new HashSet();
s.add(20);
s.add("abc");
for( _____ m:s)
System.out.println(m);
}
} 1 0
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
Enumeration is having remove() method.
State True or False.
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
The add method of Set returns false if you try to
add a duplicate element.
Carefully read the question and answer MCA Line 1 has Line 2 has run In Line 4 null Line 4 has 0.5 0
accordingly. compilation time pointer neither error
As per the below code find which statements error exceptions exception will nor
are true. occur as exceptions.
public class Test { String string
public static void main(String[] args) { contains null
Line 1: ArrayList<String> myList=new value
List<String>();
Line 2: String string = new String();
Line 3: myList.add("string");
Line 4: int index = myList.indexOf("string");
System.out.println(index);
}
}
0 0.5
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
State TRUE or FALSE.
line 1: public class Test {
line 2: public static void main(String[] args) {
line 3: Queue queue = new LinkedList();
line 4: queue.add("Hello");
line 5: queue.add("World");
line 6: List list = new ArrayList(queue);
line 7: System.out.println(list); }
line 8: }
Above code will give run time error at line
number 3.
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
The LinkedList class supports two constructors.

Carefully read the question and answer MCA Hash Map Array List Collection Sorted Map 0 0
accordingly.
Which of these are interfaces in the collection
framework 0.5 0.5
Carefully read the question and answer MCA java.utill.Map java.util.Array java.util.Dictio java.util.Hash 0 0
accordingly. List nary Map
Which collection class allows you to associate
its elements with key values 0.5 0.5
Carefully read the question and answer MCA Serializable SortTable SortedSet Comparable 0 0
accordingly.
TreeSet uses which two interfaces to sort the
data 0.5 0.5
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Iterator i= new HashMap().entrySet().iterator();
is this correct declaration

Carefully read the question and answer MCA The elements The elements The elements HashSet 0 0.5
accordingly. in the in the in the allows at most
Which statement are true for the class collection are collection arecollection are one null
HashSet? accessed guaranteed to accessed element
using a be unique using a
unique key. unique key. 0 0.5
Carefully read the question and answer MCA All All All all 0.33 0.33
accordingly. implementatio implementatio implementatio implementatio
which are the Basic features of ns are ns support ns are ns are
implementations of interfaces in Collections unsynchronize having null serializable immutable
Framework in java? d elements. and cloneable and supports
duplicates
data 0.33 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
Map is the super class of Dictionary class?
Carefully read the question and answer MCA for loop list Iterator foreach Iterator 0 0
accordingly.
what is the way to iterate over the elements of
a Map 0.5 0.5
Carefully read the question and answer MCQ Both the Statement A Statement A Both the 0 0
accordingly. Statements A is true and is false and statements A
Consider the following Statements: and B are true Statement B Statement B and B are
Statement A: The Iterator interface declares is false is true false.
only two methods: hasMoreElements and
nextElement.
Statement B: The ListIterator interface extends
both the List and Iterator interfaces.
Which of the following option is correct
regarding above given statements? 0 1
Carefully read the question and answer MCQ A B C D E 0 0
accordingly.
Consider the following list of code:
A) Iterator iterator =
hashMap.keySet().iterator();
B) Iterator iterator = hashMap.iterator();
C) Iterator iterator =
hashMap.keyMap().iterator();
D) Iterator iterator =
hashMap.entrySet().iterator();
E) Iterator iterator =
hashMap.entrySet.iterator();
Assume that hashMap is an instance of
HashMap type collection implementation.
Which of the following option gives the correct
partial code about getting an Iterator to the
HashMap entries? 0 1 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
List<Integer> newList=new
ArrayList<integer>(); will Above statement
create a new object of Array list successfully ?

Carefully read the question and answer MCQ TRUE FALSE 0 1


accordingly.
Is "Array" a subclass of "Collection" ?
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
Is this true or false. Map interface is derived
from the Collection interface.
Carefully read the question and answer MCQ True False None of the 0 0
accordingly. listed options
What will be the output for following code?
public class Compare
{
public static void main(String[]args)
{
String s=new String("abc");
String s1=new String("abc");
System.out.println(s.compareTo(s1));
}
} 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Method keySet() in Map returns a set view of
the keys contained in that map.
State True or False.
Carefully read the question and answer MCQ 1&2 1&3 2&3 1&4 2&4 0 1
accordingly.
Which of the following are synchronized?
1.Hashtable
2.Hashmap
3.Vector
4.ArrayList 0 0 0
Carefully read the question and answer MCQ Both Statement A Statement A Both 0 1
accordingly. Statements A is true and is false and Statements A
Consider the following statements about the and B are true Statement B Statement B and B are
Map type Objects: is false is true false
Statement A: Changes made in the set view
returned by keySet() will be reflected in the
original map.
Statement B: All Map implementations keep
the keys sorted.
Which of the following option is true regarding
the above statements? 0 0
Carefully read the question and answer MCQ comparator compare compareTo compareWith 0 0
accordingly.
When comparable interface is used which
method should be overridden? 1 0
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
Iterator is having previous() method.
State True or False.
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
The ArrayList<String> is immutable.
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
StringTokenizer implements the Enumeration
interface
Carefully read the question and answer MCQ both strings both strings compilation Runtime error 1 0
accordingly. are equal are not equal error
What will be the output for following code?
public class StringCompare{
public static void main(String[]args){
if("string"=="string")
System.out.println("both strings are equal");
else
System.out.println("both strings are not
equal");
}
} 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
The APIS of StringBuffer are synchronized
unlike that of StringBuilder
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State whether TRUE or FALSE.
StringBuilder is not thread-safe unlike
StringBuffer
Carefully read the question and answer MCQ true true false true false false true false 0 1
accordingly.
What will be the output for following code?
public class StringBuffer1
{
public static void main(String[]args)
{
StringBuffer s1=new StringBuffer("welcome");
StringBuffer s2=new StringBuffer("welcome");
System.out.println(s1.equals(s2));
System.out.println(s1.equals(s1));
}
}

0 0
Carefully read the question and answer MCQ both strings both strings compilation Strings cannot 0 1
accordingly. are equal are not equal error be compare
What will be the output for following code? using ==
public class CompareStrings{ operator
public static void main(String[]args){
String a=new String("string");
String s=new String("string");
if(a==s)
System.out.println("both strings are equal");
else
System.out.println("both strings are not
equal");
}
} 0 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
State whether TRUE or FALSE.
String class do not provides a method which is
used to compare two strings lexicographically.

Carefully read the question and answer MCQ Statement I & Statement I is Statement I is Statement I & 1 0
accordingly. II are TRUE TRUE & II is FALSE & II is II are FASLE
Choose the correct option. FALSE TRUE
Statement I: StringBuilder offers faster
performance than StringBuffer
Statement II: All the methods available on
StringBuffer are also available on StringBuilder
0 0
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
endsWith() member methods of String class
creates new String object. State True or False

Carefully read the question and answer MCQ Statement I & Statement I is Statement I is Statement I & 0 1
accordingly. II are TRUE TRUE & II is FALSE & II is II are FASLE
Choose the correct option. FALSE TRUE
Statement I: StringBuffer is efficient than “+”
concatenation
Statement II: Using API’s in StringBuffer the
content and length of String can be changed
which intern creates new object. 0 0
Carefully read the question and answer MCQ FALSE TRUE 0 1
accordingly.
State whether TRUE or FALSE.
String s = new String(); is valid statement in
java
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
Consider the following code snippet:
String thought = "Green";
StringBuffer bufferedThought = new
StringBuffer(thought);
String secondThought =
bufferedThought.toString();
System.out.println(thought ==
secondThought);
Which of the following option gives the output
of the above code snippet?
Carefully read the question and answer MCQ Comparing Searching Extracting All of above 0 0
accordingly. strings strings strings
String class contains API used for 0 1
Carefully read the question and answer MCQ Error x = Java x = Rules x = Java 0 0
accordingly. Rules
What is the output of below code:
package p1;
public class Hackathon {
public static void main(String[] args) {
String x = "Java";
x.concat(" Rules!");
System.out.println("x = " + x);
}
} 0 1
Carefully read the question and answer MCQ both strings both strings compilation Strings cannot 0 1
accordingly. are equal are not equal error be compare
What will be the output for following code? using ==
public class CompareStrings{ operator
public static void main(String[]args){
if(" string ".trim()=="string")
System.out.println("both strings are equal");
else
System.out.println("both strings are not
equal");
}
} 0 0
Carefully read the question and answer MCQ 4 5 6 None of the 0 1
accordingly. listed options
What will be the output for following code?
import java.util.*;
public class StringTokens
{
public static void main(String[]args)
{
String s="India is a\n developing country";
StringTokenizer o=new StringTokenizer(s);
System.out.println(o.countTokens());
}
} 0 0
Carefully read the question and answer MCQ x = JAVA x="" x = Java x="JAVA" 0 0
accordingly.
What is the output of below code:
package p1;
public class Hackathon {
public static void main(String[] args) {
String x = "Java";
x.toUpperCase();
System.out.println("x = " + x);
}
} 1 0
Carefully read the question and answer MCQ 1&2 1&2&3 1&3 2 2&3 1 0
accordingly.
What will be the output for following code?
public class Exe3
{
public static void main(String[]args)
{
try
{
int i=10;
int j=i/0;
return;
}catch(Exception e)
{
System.out.println("welcome");
}
System.out.println("error");
}
}
1.welcome
2.error
3.compilation error 0 0 0
Carefully read the question and answer MCQ welcome error compilation None of the 1 0
accordingly. error listed options
What will be the output for following code?
public class Exe3 {
public static void main(String[]args){
try{
int i=10;
int j=i/0;
return;
}catch(Exception e){
try{
System.out.println("welcome");
return;
}catch(Exception e1){
}
System.out.println("error");
}
}
} 0 0
Carefully read the question and answer MCQ IOException compilation Runtime error None of the 0 1
accordingly. error listed options
What will be the output for following code?
class super5{
void Get()throws Exception{
System.out.println("IOException");
}
}
public class Exception2 extends super5{
public static void main(String[]args){
super5 o=new super5();
try{
o.Get();
}catch(IOException e){
}
}
} 0 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
Propagating exceptions across modules is not
possible without throw and throws keyword.
State True or False.
Carefully read the question and answer MCQ 1&2 1&2&3 1&3&4 1&2&4 2&4 0 0
accordingly.
What will be the output of following code?
public class Exception1{
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
} catch(ArithmeticException e) {
System.out.println(0);
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
} catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
1.0
2.1
3.3
4.4.
1 0 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
try and throws keywords are used to manually
throw an exception?
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
RuntimeException is the superclass of those
exceptions that can be thrown during the
normal operation of the Java Virtual Machine.
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Error is the sub class of Throwable
Carefully read the question and answer MCQ throws catch ( throws No code is 0 0
accordingly. RuntimeExce Exception e ) Exception necessary.
At Point X in below code, which code is ption
necessary to make the code compile?
public class Test
{
class TestException extends Exception {}
public void runTest() throws TestException {}
public void test() /* Point X */
{
runTest();
}
}
1 0
Carefully read the question and answer MCQ Shows Shows Demands a Demands a 0 0
accordingly. unhandled unhandled finally block at finally block at
Consider the following code: exception type exception type line number 4 line number 5
1 public class FinallyCatch { IOException IOException
2 public static void main(String args[]) { at line number at line number
3 try { 4 5
4 throw new java.io.IOException();
5 }
6 }
7 }
Which of the following is true regarding the
above code? 0 1
Carefully read the question and answer MCA A NoClassDefF NoClassDefF None of the 0.5 0.5
accordingly. ClassNotFoun oundError oundError is a options
Which is/are true among given statements dException is means that subClass of
thrown when the class was ClassNotFoun
the reported found by the dException
class is not ClassLoader
found by the however
ClassLoader when trying to
in the load the class,
CLASSPATH. it ran into an
error reading
the class
definition. 0 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
is it valid to place some code in between try
and catch blocks.
Carefully read the question and answer MCQ Throwable throws throw RuntimeExce 1 0
accordingly. ption
Which is the super class for Exception and
Error? 0 0
Carefully read the question and answer MCA An exception The use of finally block The death of 0.33 0.33
accordingly. arising in the System.exit() will be always the thread
If you put a finally block after a try and its finally block executed in
associated catch blocks, then once execution itself any
enters the try block, the code in that finally circumstances
block will definitely be executed except in some .
circumstances.select the correct circumstance
from given options: 0 0.33
Carefully read the question and answer MCQ 1&2 1&3 2&3 1&4 2&4 1 0
accordingly.
Which of the following are checked
exceptions?
1.ClassNotFoundException
2.InterruptedException
3.NullPointerException
4.ArrayIndexOutOfBoundsException 0 0 0
Carefully read the question and answer MCQ An exception A catch block Both catch All of the 0 0
accordingly. which is not can have block and listed options
Which of the following statement is true handled by a another try finally block
regarding try-catch-finally? catch block block nested can throw
will be inside exceptions
handled by
subsequent
catch blocks 0 1
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
The finally block always executes when the try
block exits.
State True or False.
Carefully read the question and answer MCQ Executing try Executing try Compile Time Runtime 0 0
accordingly. After try Runtime Exception Exception
What will be the output of following code? Executing Exception
try catch
{
System.out.println("Executing try");
}
System.out.println("After try");
catch (Exception ex)
{
System.out.println("Executing catch");
}
1 0
Carefully read the question and answer MCQ 2 3 compilation 0 0
accordingly. error
What will be the output for following code?
public class Exception1{
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
} catch(Exception e) {
System.out.println(2);
} catch(ArithmeticException e) {
System.out.println(0);
}
finally {
System.out.println(3);
}
}
} 1
Carefully read the question and answer MCQ hello 0 hello 0 Math hello Math hello string 0 0
accordingly. stopped problem occur problem occur problem occur
What will be the output of the below code? stopped string problem stopped
public class Test { occur problem
public static void main(String[] args) { occurs
int a = 5, b = 0, c = 0; stopped
String s = new String();
try {
System.out.print("hello ");
System.out.print(s.charAt(0));
c = a / b;
} catch (ArithmeticException ae) {
System.out.print(" Math problem occur");
} catch (StringIndexOutOfBoundsException
se) {
System.out.print(" string problem occur");
} catch (Exception e) {
System.out.print(" problem occurs");
} finally {
System.out.print(" stopped");
}
}
} 0 1
Carefully read the question and answer MCQ try finally throw throwable 0 0
accordingly.
Which of these keywords is used to explicitly
throw an exception? 1 0
Carefully read the question and answer MCQ A,C A Compilation None of the 0 1
accordingly. error listed options
What will be the output for following code?
public class Exception1
{
public static void main(String[]args)
{
System.out.println("A");
try
{
System.exit(0);
}catch(Exception e)
{
System.out.println("B");
}
System.out.println("C");
}
}
} 0 0
Carefully read the question and answer MCA IOException Throwable RunTimeExce FileNotFindEx 0.33 0
accordingly. ption ception
which of these are the subclass of Exception
class 0.33 0.33
Carefully read the question and answer MCA try final thrown catch 0.5 0
accordingly.
Which of these keywords are a part of
exception handling? 0 0.5
Carefully read the question and answer MCQ Prints Compiler time Compile time Run time error 1 0
accordingly. Exception error User error Cannot test() method
Consider the following code: defined use does not
class MyException extends Throwable { } exceptions Throwable to throw a
public class TestThrowable { should extend catch the Throwable
public static void main(String args[]) { Exception exception instance
try {
test();
} catch(Throwable ie) {
System.out.println("Exception");
}
}

static void test() throws Throwable {


throw new MyException();
}
}
Which of the following option gives the output
for the above code? 0 0
Carefully read the question and answer MCQ exception Compilation finally finally 0 0
accordingly. finished fails exception
What will be the output of the program? finished
public class Test {
public static void aMethod() throws Exception {
try {
throw new Exception();
} finally {
System.out.print("finally");
}
}
public static void main(String args[]) {
try {
aMethod();
} catch (Exception e) {
System.out.print("exception ");
}
System.out.print("finished"); /* Line 24 */
}
}
0 1
Carefully read the question and answer MCA Runtime Runtime RuntimeExce RunTimeExce 0.5 0.5
accordingly. exceptions exceptions ption is a ption are the
what are true for RuntimeException need not be include class of I/O exceptions
explicitly arithmetic exception which forces
caught in try exceptions, the
catch block as pointer programmer
it can occur exceptions to catch them
anywhere in a explicitly in try-
program. catch block
0 0
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
Within try block if System.exit(0) is called then
also finally block is going to be executed.
State True or False.

Carefully read the question and answer MCQ TRUE FALSE 1 0


accordingly.
select true or false . Statement : Throwable is
the super class of all exceptional type classes.

Carefully read the question and answer MCQ 1&2 1&5 2&3 1&4 2&4 0 0
accordingly.
Select two runtime exceptions.
1.SQLException
2.NullPointerException
3.FileNotFoundException
4.ArrayIndexOutOfBoundsException
5.IOException 0 0 1
Carefully read the question and answer MCA Try block if exception catch block is after switching 0 0
accordingly. always occurs, not mandate from try block
which are true for try block needed a control always only to catch block
catch block switches to finally the control
followed following first followed by try never come
Catch block can be back to try
executed block to
execute rest
of the code
0.5 0.5
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Try can be followed with either catch or finally.
State True or False.

Carefully read the question and answer MCA A checked error and Checked All runtime 0.5 0
accordingly. exception is a checked exceptions exceptions
which are correct for checked exceptions subclass of exceptions are the object are checked
throwable are same. of the exceptions
class Exception
class or any of
its subclasses
except
Runtime
Exception
class.
0.5 0
Carefully read the question and answer MCQ Compile time A A,C Runtime error 1 0
accordingly. error
What will be the output for following code?
import java.io.*;
public class Exception1
{
public static void main(String[]args)
{
System.out.println("A");

try
{
}
catch(IOException t)
{
System.out.println("B");
}

System.out.println("C");
}
} 0 0
Carefully read the question and answer MCQ Both Statement A Statement A Both 1 0
accordingly. Statements A is true and is false and Statements A
Which of the following statement is true and B are true Statement B Statement B and B are
regarding implementing user defined exception is false is true false
mechanisms?
Statement A: It is valid to derive a class from
java.lang.Exception
Statement B: It is valid to derive a class from
java.lang.RuntimeException 0 0
Carefully read the question and answer MCA Class Cast Array Index ClassNotFoun Number 0.33 0.33
accordingly. Exception Out Of dException Format
which are the Unchecked exceptions Bounds Exception
Exception 0 0.33
Carefully read the question and answer MCQ IOException FileNotFound SQLException NullPointerEx 0 0
accordingly. Exception ception
Which of the following exception is not
mandatory to be handled in code? 0 1
Carefully read the question and answer MCQ statement statement statement statement 0 1
accordingly. 1:true 1:false 1:false 1:true
Statement 1:static variables can be serialized statement2:tru statement2:tru statement2:fal statement2:fal
Statement2:transient variables cannot be e e se se
serialized
which of the following is true?
0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
State TRUE or FALSE.
getParent() gives the parent directory of the file
and isFile() Tests whether the file denoted by
the given abstract pathname is a normal file.

Carefully read the question and answer MCQ DataInput ObjectInput ObjectFilter FileFilter 0 0
accordingly.
Which of these interface is not a member of
java.io package? 1 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
BufferedWriter constructor CAN ACCEPT
Filewriter Object as a parameter.
State True or False.
Carefully read the question and answer MCA File Writer Reader OutputStream 0 0.33
accordingly.
Which of these class are related to input and
output stream in terms of functioning? 0.33 0.33
Carefully read the question and answer MCQ java/system /java/system system compilation 0 0
accordingly. error
What is the output of this program?
1. import java.io.*;
2. class files {
3. public static void main(String args[]) {
4. File obj = new File("/java/system");
5. System.out.print(obj.getName());
6. }
7. }
1 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
isFile() returns true if called on a file or when
called on a directory
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Serialization is representing object in a
sequence of bytes. State True or False.
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
An ObjectInputStream deserializes objects
previously written using an
ObjectOutputStream.
State True or False.
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
InputStream is the class used for stream of
characters.
State True or False.
Carefully read the question and answer MCA BufferedOutp setting up it has flush() As bytes from 0.33 0.33
accordingly. utStream BufferedOutp method the stream are
select the correct statements about class is a utStreaman , read or
BufferedOutputStream class member of an application skipped, the
Java.io can write internal buffer
package bytes to the is refilled as
underlying necessary
output stream from the
without contained
necessarily input stream,
causing a call many bytes at
to the a time.
underlying
system for
each byte
written. 0.33 0
Carefully read the question and answer MCQ Runnable Serializable Externalizable None of the 0 1
accordingly. listed options
Which of the following is a marker interface
used for object serialization? 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
DataInputStream is not necessarily safe for
multithreaded access.
Carefully read the question and answer MCA ObjectInput StringReader File String 0 0.5
accordingly.
Which of these class are the member class of
java.io package? 0.5 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
InputStreamReader is sub class of
FilterReader.
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
The InputStream.close() method closes this
stream and releases all system resources
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Serialization is JVM independent.State True or
False.
Carefully read the question and answer MCQ 1&2 1&2&3 1&3&4 1&2&4 2&4 0 0
accordingly.
Which of the following are abstract classes?
1.Reader
2.InputStreamReader
3.InputStream
4.OutputStream 1 0 0
Carefully read the question and answer MCQ 10 11 12 None of the 0 1
accordingly. listed options
What is the value of variable "I" after execution
of following code?
public class Evaluate
{
public static void main(String[]args)
{
int i=10;
if(((i++)>12)&&(++i<15))
System.out.println(i);
else
System.out.println(i);
}
} 0 0
Carefully read the question and answer MCQ switch continue break label branch 1 0
accordingly.
_____________ is a multi way branch
statement 0 0 0
Carefully read the question and answer MCQ 100 Compilation code will runtime 0 1
accordingly. error execute with Exception
What will be the output for following code? out printing
public class Wrapper11
{
public static void main(String[]args)
{
Long l=100;
System.out.println(l);
}
} 0 0
Carefully read the question and answer MCQ True False Compilation Runtime 1 0
accordingly. error Exception
What will be the output for following code?
public class WrapperClass12
{
public static void main(String[]args)
{
Boolean b=true;
boolean a=Boolean.parseBoolean("tRUE");
System.out.println(b==a);
}
} 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
We can use Wrapper objects of type int, short,
char in switch case.
State True or False.
Carefully read the question and answer MCQ The number 2 4 8 64 0 0
accordingly. of bytes is
What is the number of bytes used by Java compiler
primitive long dependent 0 1 0
Carefully read the question and answer MCQ by value by reference Both by value none of these 1 0
accordingly. & reference
Data can be passed to the function ____ 0 0
Carefully read the question and answer MCQ switch for while do …. While for..each 0 0
accordingly.
Which of the following is a loop construct that
will always be executed once? 0 1 0
Carefully read the question and answer MCQ 10Bangalore 10 Compilation Runtime 0 0
accordingly. error Exception
What will be the output for following code?
public class WrapperClass1 {
public static void main(String[]args){
String s="10Bangalore";
int i=Integer.parseInt(s);
System.out.println(i);
}
} 0 1
Carefully read the question and answer MCQ compiles and compilation Runtime Error compiles and 1 0
accordingly. print 3 error prints 12
What will be the output for following code?
public class Wrapper2 {
public static void main(String[]args){
Byte b=1;
Byte a=2;
System.out.println(a+b);
}
} 0 0
Carefully read the question and answer MCQ True False compilation None of the 0 1
accordingly. error listed options
What will be the output for following code?
public class WrapperClass1 {
public static void main(String[]args){
Integer i=new Integer(10);
Integer j=new Integer(10);
System.out.println(i==j);
}
} 0 0
Carefully read the question and answer MCQ 10.98730.765 10.9873.765 Compilation 10.987 1 0
accordingly. error
The result of 10.987+”30.765” is
_________________. 0 0
Carefully read the question and answer MCQ compilation 0,6 6,0 0,5 0 1
accordingly. error
What will be the output for following code?
public class While {
static int i;
public static void main(String[]args){
System.out.println(i);
while(i<=5){
i++;
}
System.out.println(i);
}
} 0 0
Carefully read the question and answer MCQ A,Z a,z 91,97 97,91 0 0
accordingly.
What will be the output for following code?
public class While {
public static void main(String[]args){
int a='A';
int i=a+32;
while(a<='Z'){
a++;
}
System.out.println(i);
System.out.println(a);
}
} 0 1
Carefully read the question and answer MCQ break Jump exit goto escape 1 0
accordingly.
The ______ statement is used inside the switch
to terminate a Statement sequence 0 0 0
Carefully read the question and answer MCQ Primitive Wrapper Primitive Wrapper None Of the 1 0
accordingly. Wrapper Primitive options
What will be the output of below code?
public class Test {
public static void main(String[] args) {
int i = 1;
Integer I = new Integer(i);
method(i);
method(I);
}
static void method(Integer I) {
System.out.print(" Wrapper");
}
static void method(int i) {
System.out.print(" Primitive");
}
} 0 0 0
Carefully read the question and answer MCQ The class The number 1 The number 2 The number 3 The program 0 1
accordingly. compiles and gets printed gets printed gets printed generates a
What happens when the following code is runs, but does with with with compilation
compiled and run. Select the one correct not print AssertionError AssertionError AssertionError error.
answer. anything.
for(int i = 1; i < 3; i++)
for(int j = 3; j >= 1; j--)
assert i!=j : i; 0 0 0
Carefully read the question and answer MCQ default break continue new none 0 1
accordingly.
Each case in switch statement should end with
________ statement 0 0 0
Carefully read the question and answer MCQ executeUpdat executeQuery execute() noexecute() 0 1
accordingly. e() ()
Which method executes a simple query and
returns a single Result Set object? 0 0
Carefully read the question and answer MCQ ResultSet Parametrized PreparedState Condition 0 0
accordingly. ment
Which object allows you to execute
parametrized queries? 1 0
Carefully read the question and answer MCQ 1&2 3&4 2&3 1&4 2&4 0 0
accordingly.
Which statements about JDBC are true?
1.JDBC has 5 types of Drivers
2.JDBC stands for Java DataBase Connectivity
3.JDBC is an API to access relational
databases, spreadsheets and flat files
4.JDBC is an API to bridge the object-relational
mismatch between OO programs and relational
databases
1 0 0
Carefully read the question and answer MCQ PreparedState Parameterize Parameterize All kinds of 1 0
accordingly. ment dStatement dStatement Statements
Which type of Statement can execute and (i.e. which
parameterized queries? CallableState implement a
ment sub interface
of Statement) 0 0
Carefully read the question and answer MCQ Connection Connection Connection Connection 0 1
accordingly. cn=DriverMan cn=DriverMan cn=DriverMan cn=DriverMan
You are using JDBC-ODBC bridge driver to ager.getConn ager.getConn ager.getConn ager.getConn
establish a connection with a database. You ection("jdbc:o ection("jdbc:o ection("jdbc:o ection("jdbc:o
have created a DSN Mydsn. Which statement dbc"); dbc:Mydsn", dbc dbc:dsn"
will you use to connect to the database? "username", ","username", ,"username",
"password"); "password"); "password"); 0 0
Carefully read the question and answer MCQ TRUE FALSE 0 1
accordingly.
The method Class.forName() is a part of JDBC
API. State True or False.
Carefully read the question and answer MCQ putConnection setConnection Connection() getConnetion( 0 0
accordingly. () () )
Connection object can be initialized using
which method of the Driver Manager class? 0 1
Carefully read the question and answer MCQ Type 1 driver Type 2 driver Type 3 driver Type 4 driver 0 0
accordingly.
Which type of driver converts JDBC calls into
the network protocol used by the database
management system directly? 0 1
Carefully read the question and answer MCQ The code will The code will Class.forNam "SELECT * 0 1
accordingly. not compile as display all e must be FROM
Which of the following is true with respect to no try catch values in mentioned Person" query
code given below? block column after must be
import java.sql.*; specified named Connection passed as
public class OracleDemo column1 statement parameter to
{ con.createStat
public static void main(String [] args) throws ement()
SQLException,ClassNotFoundException
{

Class.forName("oracle.jdbc.driver.OracleDriver
");
Connection
con=DriverManager.getConnection("jdbc:oracl
e:thin:@PC188681:1521:training","scott","tiger"
);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT *
FROM Person");
while(rs.next())
{
System.out.println(rs.getString("column1"));
}
}
}
0 0
Carefully read the question and answer MCQ JDBC drivers ODBC drivers Both A and B None of the 0 1
accordingly. above
The JDBC-ODBC Bridge driver translates the
JDBC API to the ODBC API and used with
which of the following: 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Type 1 & Type 3 driver types are not vendor
specific implementation of Java driver. State
True or False
Carefully read the question and answer MCQ executeUpdat executeQuery execute() noexecute() 0 0
accordingly. e() ()
Which method executes an SQL statement that
may return multiple results? 1 0
Carefully read the question and answer MCQ connection.sql db.sql pkg.sql java.sql 0 0
accordingly.
Which package contains classes that help in
connecting to a database, sending SQL
statements to the database, and processing the
query results 0 1
Carefully read the question and answer MCQ initialized started paused stopped 1 0
accordingly.
What is the state of the parameters of the
PreparedStatement object when the user clicks
on the Query button? 0 0
Carefully read the question and answer MCQ java.util.Date java.sql.Date java.sql.Time java.sql.Times 0 0
accordingly. tamp
Which of the following listed option gives the
valid type of object to store a date and time
combination using JDBC API? 0 1
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
If your JDBC Connection is in auto-commit
mode, which it is by default, then every SQL
statement is committed to the database upon
its completion. State True or False.
Carefully read the question and answer MCQ Call method Call method Call method Call method 1 0
accordingly. execute() on a executeProce execute() on a run() on a
How can you execute a stored procedure in the CallableState dure() on a StoredProced ProcedureCo
database? ment object Statement ure object mmand object
object 0 0
Carefully read the question and answer MCQ ResultSet Parametrized TableStateme Condition 1 0
accordingly. nt
Which object provides you with methods to
access data from the table? 0 0
Carefully read the question and answer MCQ DDL To execute DDL Support for 1 0
accordingly. statements DDL statements DDL
What is correct about DDL statements? are treated as statements, cannot be statements
normal SQL you have to executed by will be a
statements, install making use of feature of a
and are additional JDBC, you future release
executed by support files should use the of JDBC
calling the native
execute() database tools
method on a for this.
Statement (or
a sub
interface
thereof) object
0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
executeUpdate() & execute() are valid methods
that can be used for executing DDL
statements. State True or False
Carefully read the question and answer MCQ ODBC written ODBC written ODBC written ODBC written 1 0
accordingly. in C language in C# in C++ in Basic
A Java program cannot directly communicate language language language
with an ODBC driver because of which of the
following: 0 0
Carefully read the question and answer MCQ Both Statement A Statement A Both 1 0
accordingly. Statement A is True and is False and Statements A
Consider the following statements: and Statement Statement B Statement B and B are
Statement A: The PreparedStatement object B are True. is False. is True. False.
enables you to execute parameterized queries.
Statement B: The SQL query can use the
placeholders which are replaced by the INPUT
parameters at runtime.
Which of the following option is True with
respect to the above statements?
0 0
Carefully read the question and answer MCQ java.jdbc and java.jdbc and java.sql and java.rdb and 0 0
accordingly. javax.jdbc java.jdbc.sql javax.sql javax.rdb
Which packages contain the JDBC classes? 1 0
Carefully read the question and answer MCQ putString() insertString() setString() setToString() 0 0
accordingly.
Which method sets the query parameters of
the PreparedStatement Object? 1 0
Carefully read the question and answer MCQ Statement PreparedState CallableState None of the 0 1
accordingly. ment ment listed options
Consider you are developing a JDBC
application, where you have to retrieve the
Employee information from the database table
based on Employee id value passed at runtime
as parameter. Which best statement API you
will use to execute parameterized SQL
statement at runtime? 0 0
Carefully read the question and answer MCQ java.util.Hash java.util.Linke java.util.List java.util.Array 0 0
accordingly. Set dHashSet List
Which collection class allows you to grow or
shrink its size and provides indexed access to
its elements, but whose methods are not
synchronized? 0 1
Carefully read the question and answer MCQ ResultSet ResultSetMet DataSource Statement 0 1
accordingly. aData
Consider you are developing a JDBC
application, where you have to retrieve
Employee table schema information like table
columns name, columns field length and data
type etc. Which API you will use to retrieve
table schema information? 0 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
In Thread implementation methods like wait(),
notify(), notifyAll() should be used in
synchronized context .
State true or false
Carefully read the question and answer MCQ Reader and InputStream Collection None of the 1 0
accordingly. Writer Stream and APIs listed options
Consider you are developing an application APIs OutputStream
where you have to store and retrieve data in Stream APIs
character format in file. Which API you will use
to store and retrieve the data in character
format? 0 0
Carefully read the question and answer MCQ TreeMap HashMap LinkedHashM Non of the 1 0
accordingly. ap listed options
Which of the following provides an efficient
means of storing key/value pairs in sorted
order, and allows rapid retrieval? 0 0
Carefully read the question and answer MCQ Statement PreparedState CallableState None of the 0 0
accordingly. ment ment listed options
Consider you are developing a JDBC
application, where you have to retrieve
quarterly report from database by executing
database store procedure created by database
developer. Which statement API you will use to
execute store procedure and retrieve ResultSet
information? 1 0
Carefully read the question and answer MCQ TRUE FALSE 1 0
accordingly.
Interfaces are mainly used to expose behavior
or functionality not the implementation code.
State true or false

Carefully read the question and answer MCQ Reduces Allows Reduces Fosters All of the 0 0
accordingly. programming interoperabilit effort to learn software listed options
Select the advantages of using Collection API’s effort y among and to use reuse
in java application development. unrelated new APIs
APIs 0 0 1
Carefully read the question and answer MCA If the equals() If the equals() If the If the 0 0.5
accordingly. method method hashCode() hashCode()
Which statements are true about comparing returns true, returns false, comparison comparison
two instances of the same class, given that the the the == returns == returns
equals() and hashCode() methods have been hashCode() hashCode() true, the true, the
properly overridden? comparison comparison equals() equals()
== might == might method must method might
return false return true return true return true 0 0.5
Carefully read the question and answer MCQ Declare the Declare the Declare the None of the 0 0
accordingly. ProgrammerA ProgrammerA ProgrammerA listed options
Consider you are developing java application in nalyst class nalyst class nalyst class
a team consists of 20 developers and you have has abstract has private has final
been asked to develop class by Name
ProgrammerAnalyst and to ensure that other
developers in team use ProgrammerAnalyst
class only by creating object and team member
should not be given provision to inherit and
modify any functionality written in
ProgrammerAnalyst class using inheritance.
How do you achieve this requirement in
development scenario? 1 0
Carefully read the question and answer MCQ finalization Serialization Synchronizati Deserializatio 0 1
accordingly. on n
Consider a development scenario where you
want to write the object data into persistence
storage devices (like file, disk etc.).Using which
of the below concept you can achieve the given
requirement? 0 0
Carefully read the question and answer MCQ By By Two thread in A thread can 0 0
accordingly. multithreading multitasking Java can have exist only in
Which of the following statement is incorrect? CPU’s idle CPU’s idle same priority two states,
time is time is running and
minimized, minimized, blocked.
and we can and we can
take take
maximum use maximum use
of it. of it. 0 1
Carefully read the question and answer MCQ Using Thread Using object Using object None of the 1 0
accordingly. Synchronizati serialization deserialization listed options
Consider you are developing an ATM on
application for ABC Bank using java
application. Several account holders of ABC
Bank have opted for add-on cards. There is a
chance that two users may access the same
account at same time and do transaction
simultaneously knowingly or unknowingly from
different ATM machine from same or different
bank branches. As developer you have to
ensure that when one user login to account
until he finishes his transaction account should
be locked to other users who are trying access
the same account. How do you implement
given requirement programmatically using
java? 0 0
Carefully read the question and answer MCQ main method finalize static block private 0 0
accordingly. method code method
Which of these is executed first before
execution of any other thing takes place in a
program? 1 0
Carefully read the question and answer MCQ Check Check Check None of the 1 0
accordingly. whether you whether you whether you listed options
Consider you are trying to persist or store have have have marked
object of Customer class using implemented implemented Customer
ObjectOutputStream class in java. When you Customer Customer class methods
are trying to persist customer object data java class with class with with
code is throwing runtime exception without Serializable Externalizable synchronized
persisting object information. Please suggest interface interface keyword
what is the key important factor you have
consider in code in order to persist customer
object data. 0 0
Carefully read the question and answer MCQ java.lang.Strin java.lang.Dou java.lang.Strin java.lang.Char 0 0
accordingly. g ble gBuffer acter
Which class does not override the equals() and
hashCode() methods, inheriting them directly
from class Object? 1 0
Carefully read the question and answer MCQ Any one will Both of them None of them It is 0 0
accordingly. be executed will be will be dependent on
What will happen if two thread of same priority first executed executed the operating
are called to be processed simultaneously? lexographicall simultaneousl system.
y y 0 1
Carefully read the question and answer MCQ FALSE TRUE 1 0
accordingly.
In Thread implementation making method
synchronized is always better in order to
increase application performance rather than
using synchronize block to synchronize certain
block of statements written in java inside the
method.
State True or False.
Carefully read the question and answer MCQ Generics Generics and When All of the 0 0
accordingly. provide type parameterized designing mentioned
Which of the following is incorrect statement safety by types your own
regarding the use of generics and shifting more eliminate the collections
parameterized types in Java? type checking need for down class (say, a
responsibilitie casts when linked list),
s to the using Java generics and
compiler. Collections. parameterized
types allow
you to achieve
type safety
with just a
single class
definition as
opposed to
defining
multiple
classes.
1 0
Carefully read the question and answer MCQ Mark Mark Make Make 1 0
accordingly. Employee Employee Employee Employee
Consider the development scenario where you class with class with class methods class methods
have created Employee class with abstract final keyword private public
implementation code and as per the project keyword
requirement you have to ensure that developer
in team reusing code written in Employee class
only using inheritance by extending the
employee class but not by creating the instance
of Employee object directly. Please suggest the
solution to implement given requirement?
0 0
Carefully read the question and answer MCQ java.util.Map java.util.Set java.util.List java.util.Collec 0 1
accordingly. tion
You need to store elements in a collection that
guarantees that no duplicates are stored and all
elements can be accessed in natural order.
Which interface provides that capability?
0 0
Carefully read the question and answer MCQ Implement Implement Implement None of the 0 1
accordingly. using Arrays using using file listed options
Consider you are developing shopping cart Collection API’s
application you have to store details of items API’s.
purchased by the each customer in
intermediate memory before storing purchase
details in actual database permanently note
that number of different items purchased by
customer is not definite it may vary. How do
you implement given requirement using java
considering best performance of the
application? 0 0

You might also like