100% found this document useful (1 vote)
3K views

Core Java-Mcqs Modified

The document contains multiple code snippets and questions about Java inheritance and access modifiers. For each code snippet or question, the correct option or output is to be selected from the given options.

Uploaded by

neko ninis
Copyright
© © All Rights Reserved
Available Formats
Download as XLS, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
3K views

Core Java-Mcqs Modified

The document contains multiple code snippets and questions about Java inheritance and access modifiers. For each code snippet or question, the correct option or output is to be selected from the given options.

Uploaded by

neko ninis
Copyright
© © All Rights Reserved
Available Formats
Download as XLS, PDF, TXT or read online on Scribd
You are on page 1/ 515

SubBaDiQuestionText

Consider the following code and choose the correct option:


class X { int x; X(int x){x=2;}}
class Y extends X{ Y(){} void displayX(){
AccesCo
System.out.print(x);}
public static void main(String args[]){
new Y().displayX();}}

Consider the following code and choose the correct option:


class Test{ private void display(){
System.out.println("Display()");}
AccesCoprivate static void show() { display();
System.out.println("show()");}
public static void main(String arg[]){
show();}}

Consider the following code and choose the correct option:


class A{ A(){System.out.print("From A");}}
AccesCoclass B extends A{ B(int z){z=2;}
public static void main(String args[]){
new B(3);}}

class One{
int var1;
One (int x){
var1 = x;
}}
class Derived extends One{
int var2;
void display(){
AccesCo
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.

Consider the following code and choose the correct option:


package aj; class A{ protected int j; }
AccesCopackage bj; class B extends A
{ public static void main(String ar[]){
System.out.print(new A().j=23);}}
class Order{
Order(){
System.out.println("Cat");
}
public static void main(String... Args){
Order obj = new Order();
System.out.println("Ant");
AccesCo}
static{
System.out.println("Dog");
}
{
System.out.println("Man");
}}
consider the code above & select the proper output from the options.

public class MyAr {


public static void main(String argv[]) {
MyAr m = new MyAr();
m.amethod();
}
AccesSi public void amethod() {
final int i1;
System.out.println(i1);
}
}
What is the Output of the Program?

class MyClass1
{
private int area(int side)
{
return(side * side);
}
public static void main(String args[ ])
AccesCo
{
MyClass1 MC = new MyClass1( );
int area = MC.area(50);
System.out.println(area);
}
}
What would be the output?
class Sample
{int a,b;
Sample()
{ a=1; b=2;
System.out.println(a+"\t"+b);
}
Sample(int x)
{ this(10,20);
a=b=x;
System.out.println(a+"\t"+b);
}
Sample(int a,int b)
AccesCo{ 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?

Consider the following code and choose the correct option:


public class MyClass {
public static void main(String arguments[]) {
amethod(arguments);
}
AccesSi public void amethod(String[] arguments) {
System.out.println(arguments[0]);
System.out.println(arguments[1]);
}
}
Command Line arguments - Hi, Hello

Given:
public class Yikes {

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) {
AccesSi
short y = 6;
long z = 7;
go(y);
go(z);
}
}
What is the result?
abstract class MineBase {
abstract void amethod();
static int i;
}
public class Mine extends MineBase {
AccesSi public static void main(String argv[]){
int[] ar=new int[5];
for(i=0;i < ar.length;i++)
System.out.println(ar[i]);
}
}

What will be the result when you attempt to compile this program?
public class Rand{
public static void main(String argv[]){
int iRand;
AccesSi
iRand = Math.random();
System.out.println(iRand);
}
}
AccesSi Which of the following declarations are correct? (Choose TWO)
class A, B and C are in multilevel inheritance hierarchy repectively . In the
AccesSi main method of some other class if class C object is created, in what
sequence the three constructors execute?

What will be the result when you try to compile and run the following code?
private class Base{
Base(){
int i = 100;
System.out.println(i);
}
}
AccesSi
public class Pri extends Base{
static int i = 200;
public static void main(String argv[]){
Pri p = new Pri();
System.out.println(i);
}
}

Suppose class B is sub class of class A:


A) If class A doesn't have any constructor, then class B also must not have
any constructor
AccesCoB) 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
What will be printed out if you attempt to compile and run the following code ?
public class AA {
public static void main(String[] args) {
int i = 9;
switch (i) {
default:
System.out.println("default");
case 0:
AccesSi System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two");
}
}
}

Consider the following code and choose the correct option:


package aj; private class S{ int roll;
S(){roll=1;} }
AccesCo
package aj; class T
{ public static void main(String ar[]){
System.out.print(new S().roll);}}

public class Q {
public static void main(String argv[]) {
int anar[] = new int[] { 1, 2, 3 };
AccesSi
System.out.println(anar[1]);
}
}

Which statements, when inserted at (1), will not result in compile-time errors?
public class ThisUsage {
int planets;
static int suns;
AccesSi public void gaze() {
int i;
// (1) INSERT STATEMENT HERE
}
}
Given the following code what will be output?
public class Pass{
static int j=20;
public static void main(String argv[]){
int i=10;
Pass p = new Pass();
p.amethod(i);
System.out.println(i);
AccesSi
System.out.println(j);
}

public void amethod(int x){


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

class Order{
Order(){
System.out.println("Cat");
}
public static void main(String... Args){
System.out.println("Ant");
}
AccesSi
static{
System.out.println("Dog");
}
{
System.out.println("Man");
}}
consider the code above & select the proper output from the options.
public class c123 {
private c123() {
System.out.println("Hellow");
}
public static void main(String args[]) {
c123 o1 = new c123();
c213 o2 = new c213();
}
AccesCo
}
class c213 {
private c213() {
System.out.println("Hello123");
}
}

What is the output?

class A {
int i, j;

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;

AccesCo 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?
public class MyAr {
static int i1;
public static void main(String argv[]) {
MyAr m = new MyAr();
m.amethod();
AccesSi }
public void amethod() {
System.out.println(i1);
}
}
What is the output of the program?

Given:
package QB;

class Meal {
Meal() {
System.out.println("Meal()");
}
}
class Cheese {
Cheese() {
System.out.println("Cheese()");
}
}
class Lunch extends Meal {
Lunch() {
System.out.println("Lunch()");
}
AccesCo}
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) {
new Sandwich();
}
} What would be the output?

Consider the following code and choose the correct option:


class A{ int a; A(int a){a=4;}}
class B extends A{ B(){super(3);} void displayA(){
AccesCo
System.out.print(a);}
public static void main(String args[]){
new B().displayA();}}
class Order{
Order(){
System.out.println("Cat");
}
public static void main(String... Args){
Order obj = new Order();
AccesSi
System.out.println("Ant");
}
static{
System.out.println("Dog");
}}
consider the code above & select the proper output from the options.

What will happen if a main() method of a "testing" class tries to access a


AccesSi
private instance variable of an object using dot notation?

What will be the result of compiling the following program?


public class MyClass {
long var;
public void MyClass(long param) { var = param; } // (Line no 1)
AccesSi public static void main(String[] args) {
MyClass a, b;
a = new MyClass(); // (Line no 2)
}
}

public class MyClass {


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

static void print(int i, String s) {


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

public static void main(String[] args) {


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

Here is the general syntax for method definition:

accessModifier returnType methodName( parameterList )


{
Java statements
AccesSi
return returnValue;
}

What is true for the returnType and the returnValue?


11. class Mud {
12. // insert code here
13. System.out.println("hi");
14. }
15. }
And the following five fragments:
AccesSi
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?

package QB;
class Sphere {
protected int methodRadius(int r) {
System.out.println("Radious is: "+r);
return 0;
}
}
AccesSi 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 ?

A) A call to instance method can not be made from static context.


AccesSi
B) A call to static method can be made from non static context.
Consider the following code and choose the correct option:
class A{ private void display(){ System.out.print("Hi");}
AccesCo
public static void main(String ar[]){
display();}}
class One{
int var1;
One (int x){
var1 = x;
}}
class Derived extends One{
int var2;
Derived(){
super(10);
var2=10;
AccesCo
}
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.

public class MyAr {


public static void main(String argv[]) {
MyAr m = new MyAr();
m.amethod();
}
AccesSi public void amethod() {
static int i1;
System.out.println(i1);
}
}
What is the Output of the Program?

Consider the following code and choose the correct option:


class A{ int z; A(int x){z=x;} }
AccesCoclass B extends A{
public static void main(String arg){
new B();}}

A) No argument constructor is provided to all Java classes by default


B) No argument constructor is provided to the class only when no constructor
AccesSi is defined.
C) Constructor can have another class object as an argument
D) Access specifiers are not applicable to Constructor

Which modifier is used to control access to critical code in multi-threaded


AccesSi
programs?
public class c1 {
private c1()
{
System.out.println("Hello");
}
public static void main(String args[])
AccesSi
{
c1 o1=new c1();
}
}

What is the output?

Which of the following sentences is true?


A) Access to data member depends on the scope of the class and the scope
of data members
AccesCo
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

Consider the following code and choose the correct option:


class Test{ private static void display(){
System.out.println("Display()");}
AccesCoprivate static void show() { display();
System.out.println("show()");}
public static void main(String arg[]){
show();}}
Consider the following code and choose the correct option:
class A{ private static void display(){ System.out.print("Hi");}
AccesCo
public static void main(String ar[]){
display();}}

AccesSi Which of the following will print -4.0

class Test{
static void method(){
this.display();
}
static display(){
System.out.println(("hello");
AccesSi
}
public static void main(String[] args){
new Test().method();
}
}
consider the code above & select the proper output from the options.
Consider the following code and choose the best option:
class Super{ int x; Super(){x=2;}}
class Sub extends Super { void displayX(){
AccesCo
System.out.print(x);}
public static void main(String args[]){
new Sub().displayX();}}

Which modifier indicates that the variable might be modified asynchronously,


AccesSi
so that all threads will get the correct value of the variable.
AccesSi A constructor may return value including class type
Consider the following code and choose the correct option:
package aj; class S{ int roll =23;
private S(){} }
AccesCo
package aj; class T
{ public static void main(String ar[]){
System.out.print(new S().roll);}}

What will happen when you attempt to compile and run this code?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}

public class Abs extends Base{


public static void main(String argv[]){
AccesCo
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My Func");
}
public void amethod(){
myfunc();
}
}
Given:
class Pizza {
java.util.ArrayList toppings;
public final void addTopping(String topping) {
toppings.add(topping);
}
}
public class PepperoniPizza extends Pizza {
Inheri Mepublic 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?

When we use both implements & extends keywords in a single java program
Inheri Me
then what is the order of keywords to follow?

Consider the following code and choose the correct option:


interface employee{
void saldetails();
void perdetails();
}
abstract class perEmp implements employee{
public void perdetails(){
Inheri Co 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(); }}

Consider the following code and choose the correct option:


interface A{
int i=3;}
interface B{
int i=4;}
Inheri Me
class Test implements A,B{
public static void main(String[] args) {
System.out.println(i);
}
}
Consider the following code:
// Class declarations:
class Super {}
class Sub extends Super {}
Inheri Me
// Reference declarations:
Super x;
Sub y;
Which of the following statements is correct for the code: y = (Sub) x?

Consider the following code and choose the correct option:


class A{
void display(){ System.out.println("Hello A"); }}
class B extends A{
void display(){
Inheri Me System.out.println("Hello B"); }}
public class Test {
public static void main(String[] args) {
A a=new B();
B b= a;
b.display(); }}

Which of these field declarations are legal in an interface? (Choose all


Inheri Me
applicable)

Consider the following code and choose the correct option:


abstract class Car{
abstract void accelerate();
}class Lamborghini extends Car{
@Override
void accelerate() {
Inheri Co
System.out.println("90 mph");
} void nitroBooster(){
System.out.print("150 mph"); }
public static void main(String[] args) {
Car mycar=new Lamborghini();
mycar.nitroBooster(); }}

Consider the code below & select the correct ouput from the options:
1. public class Mountain {
2. protected int height(int x) { return 0; }
3. }
4. class Alps extends Mountain {
5. // insert code here
6. }
Inheri Me
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; }
Consider the following code and choose the correct option:
class A{
void display(byte a, byte b){
System.out.println("sum of byte"+(a+b)); }
Inheri Me
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); }}

Consider the following code and choose the correct option:


interface console{
int line;
void print();}
Inheri Meclass a implements console{
public void print(){
System.out.print("A");}
public static void main(String ar[]){
new a().print();}}

Consider the following code and choose the correct option:


class A{
void display(){ System.out.println("Hello A"); }}
class B extends A{
void display(){
Inheri Me System.out.println("Hello B"); }}
public class Test {
public static void main(String[] args) {
A a=new B();
B b= (B)a;
b.display(); }}

Inheri MeWhich of the following defines a legal abstract class?

Inheri MeChoose the correct declaration of variable in an interface:

Given:
11. class ClassA {}
12. class ClassB extends ClassA {}
13. class ClassC extends ClassA {}
and:
Inheri Me21. 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.)
Consider the following code and choose the correct option:
class A{
void display(){ System.out.println("Hello A"); }}
class B extends A{
void display(){
Inheri Me
System.out.println("Hello B"); }}
public class Test {
public static void main(String[] args) {
B b=(B) new A();
b.display(); }}

Inheri MeA class Animal has a subclass Mammal. Which of the following is true:

Given:
interface DeclareStuff {
public static final int Easy = 3;
void doStuff(int t); }
public class TestDeclare implements DeclareStuff {
public static void main(String [] args) {
int x = 5;
Inheri Me
new TestDeclare().doStuff(++x);
}
void doStuff(int s) {
s += Easy + ++s;
System.out.println("s " + s);
}
} What is the result?

Consider the following code and choose the correct option:


interface console{
int line=10;
void print();}
Inheri Meclass a implements console{
void print(){
System.out.print("A");}
public static void main(String ar[]){
new a().print();}}

Inheri MeWhich of the following is correct for an abstract class. (Choose TWO)

Which declaration can be inserted at (1) without causing a compilation error?


interface MyConstants {
int r = 42;
Inheri Me
int s = 69;
// (1) INSERT CODE HERE
}
Given :

Day d;
BirthDay bd = new BirthDay("Raj", 25);
Inheri Me
d = bd; // Line X

Where Birthday is a subclass of Day. State whether the code given at Line X
is correct:

class Animal {
void makeNoise() {System.out.println("generic noise"); }
}
class Dog extends Animal {
void makeNoise() {System.out.println("bark"); }
void playDead() { System.out.println("roll over"); }
}
Inheri Me
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.

interface Vehicle{
void drive();
}
final class TwoWheeler implements Vehicle{
int wheels = 2;
public void drive(){
System.out.println("Bicycle");
}
}
Inheri Meclass 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.

Inheri MeSelect the correct statement:


Consider the code below & select the correct ouput from the options:
class A{
static int sq(int n){
return n*n; }}
Inheri Mepublic 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)); }}

Given:
Inheri Mepublic static void main( String[] args ) { SomeInterface x; ... }
Can an interface name be used as the type of a variable

Given :
What would be the result of compiling and running the following program?
// Filename: MyClass.java
public class MyClass {
public static void main(String[] args) {
C c = new C();
System.out.println(c.max(13, 29));
}
}
Inheri Me
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); }
}

Given:
interface A { public void methodA(); }
interface B { public void methodB(); }
interface C extends A,B{ public void methodC(); } //Line 3
class D implements B {
public void methodB() { } //Line 5
Inheri Co}
class E extends D implements C { //Line 7
public void methodA() { }
public void methodB() { } //Line 9
public void methodC() { }
}
What would be the result?
Inheri MeSelect the correct statement:

class Animal {
void makeNoise() {System.out.println("generic noise"); }
}
class Dog extends Animal {
void makeNoise() {System.out.println("bark"); }
void playDead() { System.out.println("roll over"); }
}
Inheri Me
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.

Consider the code below & select the correct ouput from the options:

class Money {
private String country = "Canada";
Inheri Mepublic 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() ); } }

Which Man class properly represents the relationship "Man has a best friend
who is a Dog"?
A)class Man extends Dog { }
Inheri Me
B)class Man implements Dog { }
C)class Man { private BestFriend dog; }
D)class Man { private Dog bestFriend; }

Consider the following code and choose the correct option:


interface Output{
void display();
void show();
}
Inheri Me
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();}}
The concept of multiple inheritance is implemented in Java by

(A) extending two or more classes


Inheri Me
(B) extending one class and implementing one or more interfaces
(C) implementing two or more interfaces
(D) all of these

Consider the following code and choose the correct option:


interface Output{
void display();
void show();
Inheri Me}
class Screen implements Output{
void display(){ System.out.println("display"); }public static void main(String[]
args) {
new Screen().display();}}

Given a derived class method which overrides one of it’s base class methods.
Inheri Me
With derived class object you can invoke the overridden base method using:

Consider the following code and choose the correct option:


abstract class Car{
abstract void accelerate();
}
class Lamborghini extends Car{
@Override
void accelerate() {
Inheri Co
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();}}

Given the following classes and declarations, which statements are true?
// Classes
class Foo {
private int i;
public void f() { /* ... */ }
public void g() { /* ... */ }
}
Inheri Me
class Bar extends Foo {
public int j;
public void g() { /* ... */ }
}
// Declarations:
Foo a = new Foo();
Bar b = new Bar();

Inheri MeAll data members in an interface are by default


Consider the given code and select the correct output:

class SomeException {
}

class A {
Inheri Me
public void doSomething() { }
}

class B extends A {
public void doSomething() throws SomeException { }
}

Given:
class A {
final void meth() {
System.out.println("This is a final method.");
}
}
class B extends A {
void meth() {
System.out.println("Illegal!");
Inheri Co }
}
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?

Consider the code below & select the correct ouput from the options:
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{
Inheri Mepublic 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()); }}
Given:
interface DoMath
{
double getArea(int r);
}
Inheri Meinterface MathPlus
{
double getVolume(int b, int h);
}
/* Missing Statements ? */
Select the correct missing statements.

interface interface_1 {
void f1();
}
class Class_1 implements interface_1 {
void f1() {
System.out.println("From F1 funtion in Class_1 Class");
}
Inheri Me
}
public class Demo1 {
public static void main(String args[]) {
Class_1 o11 = new Class_1();
o11.f1();
}
}

interface A{}
class B implements A{}
class C extends B{}
public class Test extends C{
Inheri Mepublic static void main(String[] args) {
C c=new C();
/* Line6 */}}

Which code, inserted at line 6, will cause a java.lang.ClassCastException?

Given the following classes and declarations, which statements are true?
// Classes
class A {
private int i;
public void f() { /* ... */ }
public void g() { /* ... */ }
}
Inheri Meclass B extends A{
public int j;
public void g() { /* ... */ }
}
// Declarations:
A a = new A();
B b = new B();
Select the three correct answers.
Inheri MeWhich of the following statements is true regarding the super() method?

Is it possible if a class definition implements two interfaces, each of which has


Inheri Me
the same definition for the constant?

Consider the code below & select the correct ouput from the options:

class Mountain{
int height;
protected Mountain(int x) { height=x; }
public int getH(){return height;}}
Inheri Me
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());
}
}

Consider the following code and choose the correct option:


interface employee{
void saldetails();
void perdetails();
}
abstract class perEmp implements employee{
Inheri Co
public void perdetails(){
System.out.println("per details"); }}
class Programmer extends perEmp{
public static void main(String[] args) {
perEmp emp=new Programmer();
emp.saldetails(); }}

Consider the following code and choose the correct option:


abstract class Fun{
void time(){
System.out.println("Fun Time"); }}
class Run extends Fun{
Inheri Co
void time(){
System.out.println("Fun Run"); }
public static void main(String[] args) {
Fun f1=new Run();
f1.time(); }}
What will be the result when you try to compile and run the following code?
class Base1 {
Base1() {
int i = 100;
System.out.println(i);
}
}
Inheri Me
public class Pri1 extends Base1 {
static int i = 200;

public static void main(String argv[]) {


Pri1 p = new Pri1();
System.out.println(i);
}
}

What will be the output of the program?

class SuperClass
{
public Integer getLength()
{
return new Integer(4);
}
}

public class SubClass extends SuperClass


{
Inheri Co 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() );
}
}
What is the output for the following code:
abstract class One{
private abstract void test();
}
class Two extends One{
void test(){
System.out.println("hello");
Inheri Me
}}
class Test{
public static void main(String[] args){
Two obj = new Two();
obj.test();
}
}

What is the output :


interface A{
void method1();
void method2();
}
class Test implements A{
Inheri Mepublic void method1(){
System.out.println("hello");}}
class RunTest{
public static void main(String[] args){
Test obj = new Test();
obj.method1();
}}

What is the result of attempting to compile and run the following code?
import java.util.Vector; import java.util.LinkedList; public class Test1{ public
static void main(String[] args) { Integer int1 = new Integer(10); Vector vec1 =
new Vector(); LinkedList list = new LinkedList(); vec1.add(int1); list.add(int1);
CollecMe
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".

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


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

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


CollecMe
s.add("g");
s.pollFirst();
s.pollFirst();
s.add("c2");
System.out.println(s.size() +" "+ subs.size());

Which collection class allows you to grow or shrink its size and provides
CollecSi indexed access to
its elements, but its methods are not synchronized?
Which statement is true about the following program?
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class WhatISThis {
public static void main(String[] na){
List<StringBuilder> list=new ArrayList<StringBuilder>();
CollecMe
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));
}
}

CollecSi static int binarySearch(List list, Object key) is a method of __________

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

CollecSi static void sort(List list) method is part of ________

Consider the code below & select the correct ouput from the options:
public class Test{
public static void main(String[] args) {
String []colors={"orange","blue","red","green","ivory"};
CollecMe
Arrays.sort(colors);
int s1=Arrays.binarySearch(colors, "ivory");
int s2=Arrays.binarySearch(colors, "silver");
System.out.println(s1+" "+s2); }}

Consider the following code was executed on June 01, 1983. What will be the
output?
class Test{
public static void main(String args[]){
CollecMe
Date date=new Date();
SimpleDateFormat sd;
sd=new SimplpeDateFormat("E MMM dd yyyy");
System.out.print(sd.format(date));}}
Consider the following code and choose the correct option:
class Data{ Integer data; Data(Integer d){data=d;}
public boolean equals(Object o){return true;}
public int hasCode(){return 1;}}
class Test{
public static void main(String ar[]){
CollecMe 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());}}

CollecSi next() method of Scanner class will return _________

Given:
public static Iterator reverse(List list) {
Collections.reverse(list);
return list.iterator();
}
public static void main(String[] args) {
CollecSi
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?

Given:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class MainClass {

public static void main(String[] a) {


CollecMe 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?
import java.util.StringTokenizer;
class ST{
public static void main(String[] args){
String input = "Today is$Holiday";
CollecSi
StringTokenizer st = new StringTokenizer(input,"$");
while(st.hasMoreTokens()){
System.out.println(st.nextElement());
}}
int indexOf(Object o) - What does this method return if the element is not
CollecSi
found in the List?
Consider the following code and choose the correct option:
class Test{
public static void main(String args[]){
Integer arr[]={3,4,3,2};
CollecMe
Set<Integer> s=new TreeSet<Integer>(Arrays.asList(arr));
s.add(1);
for(Integer ele :s){
System.out.println(ele); } }}

A) It is a good practice to store heterogenous data in a TreeSet.


B) HashSet has default initial capacity (16) and loadfactor(0.75)
CollecMe
C)HashSet does not maintain order of Insertion
D)TreeSet maintains order of Inserstion

Consider the following code and choose the correct option:


class Test{
public static void main(String args[]){
TreeSet<Integer> ts=new TreeSet<Integer>();
ts.add(1);
ts.add(8);
CollecMe ts.add(6);
ts.add(4);
SortedSet<Integer> ss=ts.subSet(2, 10);
ss.add(9);
System.out.println(ts);
System.out.println(ss);
}}

Inorder to remove one element from the given Treeset, place the appropriate
line of code
public class Main {
public static void main(String[] args) {
TreeSet<Integer> tSet = new TreeSet<Integer>();
System.out.println("Size of TreeSet : " + tSet.size());
tSet.add(new Integer("1"));
CollecSi
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());
}
}
A)Property files help to decrease coupling
B) DateFormat class allows you to format dates and times with customized
styles.
CollecMe
C) Calendar class allows to perform date calculation and conversion of dates
and times between timezones.
D) Vector class is not synchronized
CollecSi Which interface does java.util.Hashtable implement?
Consider the following code and choose the correct option:
public static void before() {
Set set = new TreeSet();
set.add("2");
set.add(3);
CollecSi
set.add("1");
Iterator it = set.iterator();
while (it.hasNext())
System.out.print(it.next() + " ");
}

Given:
import java.util.*;

public class LetterASort{


public static void main(String[] args) {
ArrayList<String> strings = new ArrayList<String>();
strings.add("aAaA");
CollecSi strings.add("AaA");
strings.add("aAa");
strings.add("AAaa");
Collections.sort(strings);
for (String s : strings) { System.out.print(s + " "); }
}
}
What is the result?

Which collection class allows you to access its elements by associating a key
CollecSi
with an element's value, and provides synchronization?
Consider the following code and select the correct output:
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class Lists {
public static void main(String[] args) {
List<String> list=new ArrayList<String>();
list.add("1");
CollecMelist.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);
}
}

Given:
public static Collection get() {
Collection sorted = new LinkedList();
sorted.add("B"); sorted.add("C"); sorted.add("A");
return sorted;
}
CollecSi
public static void main(String[] args) {
for (Object obj: get()) {
System.out.print(obj + ", ");
}
}
What is the result?

You wish to store a small amount of data and make it available for rapid
access. You do not have a need for the data to be sorted, uniqueness is not
an issue and the data will remain fairly static Which data structure might be
most suitable for this requirement?
CollecMe
1) TreeSet
2) HashMap
3) LinkedList
4) an array
Given:
10. interface A { void x(); }
11. class B implements A {
public void x() { }
public void y() { } }
12. class C extends B {
public void x() {} }
And:
CollecMe
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?

A) Iterator does not allow to insert elements during traversal


B) Iterator allows bidirectional navigation.
CollecMe
C) ListIterator allows insertion of elements during traversal
D) ListIterator does not support bidirectional navigation

What will be the output of following code?


class Test{
public static void main(String args[]){
TreeSet<Integer> ts=new TreeSet<Integer>();
ts.add(2);
ts.add(3);
CollecMe
ts.add(7);
ts.add(5);
SortedSet<Integer> ss=ts.subSet(1,7);
ss.add(4);
ss.add(6);
System.out.print(ss);}}

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

Consider the following code and choose the correct output:


class Test{
public static void main(String args[]){
TreeMap<Integer, String> hm=new TreeMap<Integer, String>();
hm.put(2,"Two");
hm.put(4,"Four");
CollecMehm.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);
}}

Which of the given options is similar to the following code:


KeywoMe
value += sum++ ;
KeywoMeWhich will legally declare, construct, and initialize an array?

Consider the code below & select the correct ouput from the options:
public class Test {
public static void main(String[] args) {
KeywoMe
String[] elements = { "for", "tea", "too" };
String first = (elements.length > 0) ?elements[0] : null;
System.out.println(first); }}

Consider the following code and choose the correct option:


class Test{
interface Y{
void display(); }
KeywoMepublic static void main(String[] args) {
new Y(){
public void display(){
System.out.println("Hello World"); }
}.display(); }}

class Test{
public static void main(String[] args){
byte b=(byte) (45 << 1);
KeywoMe
b+=4;
System.out.println(b); }}
What should be the output for the code written above?
What is the value of y when the code below is executed?
KeywoMeint a = 4;
int b = (int)Math.ceil(a % 3 + a / 3.0);

Consider the following code and choose the correct option:


class Test{
interface Y{
void display(); }
KeywoMepublic static void main(String[] args) {
Y y=new Y(){
public void display(){
System.out.println("Hello World"); } };
y.display(); }}

What is the output of the following program?


public class demo {
public static void main(String[] args) {
int arr[5];
for (int i = 0; i < arr.length; i++) {
arr[i] = arr[i] + 10;
KeywoMe
}
for (int j = 0; j < arr.length; j++)
System.out.println(arr[j]);

}
}
What will be the result of the following program?
public class Init {
String title;
boolean published;
static int total;
static double maxPrice;
public static void main(String[] args) {
KeywoMeInit initMe = new Init();
double price;
if (true)
price = 100.00;
System.out.println("|" + initMe.title + "|" + initMe.published + "|" +
Init.total + "|" + Init.maxPrice + "|" + price+ "|");
}
}

Consider the following code and choose the correct option:


class Test{
static class A{
interface X{
KeywoMe int z=4; } }
static void display(){
System.out.println(A.X.z); }
public static void main(String[] args) {
display(); }}

Here is the general syntax for method definition:

accessModifier returnType methodName( parameterList )


{
Java statements
KeywoMe
return returnValue;
}

What is true for the returnType and the returnValue?

class C{
public static void main (String[] args) {
byte b1=33; //1
b1++; //2
KeywoMebyte b2=55; //3
b2=b1+1; //4
System.out.println(b1+""+b2);
}}
Consider the code above & select the correct output.
What will be the output of the program?

public class CommandArgs


{
public static void main(String [] args)
{
String s1 = args[1];
String s2 = args[2];
KeywoMe 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

A) The purpose of the method overriding is to perform different operation,


though input remains the same.
KeywoMe
B) one of the important Object Oriented principle is the code reusability that
can be achieved using abstraction
Consider the following code snippet:
int i = 10;
KeywoMe
int n = ++i%5;
What are the values of i and n after the code is executed?
Consider the following code and choose the correct option:
class Test{
class A{ static int x=3; }
KeywoMestatic void display(){
System.out.println(A.x); }
public static void main(String[] args) {
display(); }}

Consider the following code and choose the correct output:

int value = 0;
KeywoMe
int count = 1;
value = count++ ;
System.out.println("value: "+ value  + " count: " + count);
What will be the output of the program?

public class CommandArgsTwo


{
public static void main(String [] argh)
{
int x;
x = argh.length;
for (int y = 1; y <= x; y++)
KeywoMe
{
System.out.print(" " + argh[y]);
}
}
}

and the command-line invocation is

> java CommandArgsTwo 1 2 3

class Test{
public static void main(String[] args){
int var;
KeywoMevar = var +1;
System.out.println("var ="+var);
}}
consider the code above & select the proper output from the options.

Consider the following code and select the correct output:


class Test{
interface Y{
void display(); }
KeywoMepublic static void main(String[] args) {
new Y(){
public void display(){
System.out.println("Hello World"); } };
}}

KeywoMeWhich of the following will declare an array and initialize it with five numbers?
KeywoMeWhich three are legal array declarations? (Choose THREE)

What is the output of the following program?


public class MyClass
{
public static void main( String[] args )
{
KeywoMeprivate static final int value =9;
float total;
total = value + value / 2;
System.out.println( total );
}
}
As per the following code fragment, what is the value of a?
String s;
KeywoMeint a;
s = "Foolish boy.";
a = s.indexOf("fool");

Consider the code below & select the correct ouput from the options:
class Test{
public static void main(String[] args) {
parse("Four"); }
static void parse(String s){
KeywoMe
try {
double d=Double.parseDouble(s);
}catch(NumberFormatException nfe){
d=0.0; }finally{
System.out.println(d); } }}

Consider the code below & select the correct ouput from the options:
class A{
public int a=7;
public void add(){
this.a+=2; System.out.print("a"); }}

public class Test extends A{


KeywoMe
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); }}

Consider the following code:


int x, y, z;
y = 1;
KeywoMe
z = 5;
x = 0 - (++y) + z++;
After execution of this, what will be the values of x, y and z?

What will be the output of the program ?

public class Test


{
public static void main(String [] args)
KeywoMe {
signed int x = 10;
for (int y=0; y<5; y++, x--)
System.out.print(x + ", ");
}
}
Consider the following code snippet:
int i = 10;
KeywoMe
int n = i++%5;
What are the values of i and n after the code is executed?
What is the output of the following:

int a = 0;
KeywoMeint b = 10;

a = --b ;
System.out.println("a: " + a + " b: " + b );

Consider the given code and select the correct output:


class Test{
public static void main(String[] args){
KeywoMe int num1 = 012;
int num2 = 0x110;
int sum =num1+=num2;
System.out.println("Ans = "+sum); }}

What will happen if you attempt to compile and run the following code?
Integer ten=new Integer(10);
Long nine=new Long (9);
KeywoMe
System.out.println(ten + nine);
int i=1;
System.out.println(i + ten);

KeywoMeWhich of the following are correct variable names? (Choose TWO)

Which of the following lines of code will compile without warning or error?
1) float f=1.3;
2) char c="a";
KeywoMe
3) byte b=257;
4) boolean b=null;
5) int i=10;

Consider the code below & select the correct ouput from the options:

public class Test {


public static void main(String [] args) {
int x = 5;
boolean b1 = true;
KeywoMe
boolean b2 = false;
if ((x == 4) && !b2 )
System.out.print("1 ");
System.out.print("2 ");
if ((b2 = true) && b1 )
System.out.print("3 "); }
Consider the code below & select the correct ouput from the options:
public class Test {
public static void main(String[] args) {
int x=5;
Test t=new Test();
KeywoMe t.disp(x);
System.out.println("main X="+x);
}
void disp(int x) {
System.out.println("disp X = "+x++);
}}

Given the following piece of code:


public class Test {
public static void main(String args[]) {
int i = 0, j = 5 ;
for( ; (i < 3) && (j++ < 10) ; i++ ) {
KeywoMeSystem.out.print(" " + i + " " + j );
}
System.out.print(" " + i + " " + j );
}
}
what will be the output?

Identify the statements that are correct:


(A) int a = 13, a>>2 = 3
KeywoMe(B) int b = -8, b>>1 = -4
(C) int a = 13, a>>>2 = 3
(D) int b = -8, b>>>1 = -4

Consider the following code and choose the correct option:


class Test{
class A{
interface X{
KeywoMe int z=4; } }
static void display(){
System.out.println(new A().X.z); }
public static void main(String[] args) {
display(); }}

Given
class MybitShift
{
public static void main(String [] args)
{
KeywoMe int a = 0x5000000;
System.out.print(a + " and ");
a = a >>> 25;
System.out.println(a);
}
}
1. public class LineUp {
2. public static void main(String[] args) {
3. double d = 12.345;
4. // insert code here
5. }
6. }
KeywoMe
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);

Here is the general syntax for method definition:

accessModifier returnType methodName( parameterList )


{
Java statements
KeywoMe
return returnValue;
}

What is true for the accessModifier?

Given classes A, B, and C, where B extends A, and C extends B, and where


all classes
KeywoMeimplement the instance method void doIt(). How can the doIt() method in A
be
called from an instance method in C?

State the class relationship that is being implemented by the following code:
class Employee
{
private int empid;
private String ename;
public double getBonus()
{
Accounts acc = new Accounts();
KeywoMe
return acc.calculateBonus();
}
}

class Accounts
{
public double calculateBonus(){//method's code}
}
Say that class Rodent has a child class Rat and another child class Mouse.
Class Mouse has a child class PocketMouse. Examine the following

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

Which one of the following will cause a compiler error?

How many objects and reference variables are created by the following lines
of code?
KeywoMeEmployee emp1, emp2;
emp1 = new Employee() ;
Employee emp3 = new Employee() ;

Consider the code below & select the correct ouput from the options:

public class Test {


int squares = 81;
public static void main(String[] args) {
KeywoMe
new Test().go(); }
void go() {
incr(++squares);
System.out.println(squares); }
void incr(int squares) { squares += 10; } }

Consider the following code and choose the correct option:


public class Test {
public static void main(String[] args) {
String Co
String name="ALDPR7882E";
System.out.println(name.endsWith("E") & name.matches("[A-Z]{5}[0-9]{4}[A-
Z]"));}}
Consider the following code and choose the correct option:
public class Test {
String Copublic static void main(String[] args) {
StringBuffer sb=new StringBuffer("YamunaRiver");
System.out.println(sb.capacity()); }}

Examine this code:

String stringA = "Wild";


String stringB = " Irish";
String Co
String stringC = " Rose";
String result;

Which of the following puts a reference to "Wild Irish Rose" in result?

A)A string buffer is a mutable sequence of characters.


String Co
B) sequece of characters in the string buffer can not be changed.
Consider the following code and choose the correct option:
class Test {
public static void main(String[] args) {
String Co 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] + " "); }}

Consider the following code and choose the correct option:


public class Test {
String Copublic static void main(String[] args) {
String name="vikaramaditya";
System.out.println(name.substring(2, 5).toUpperCase().charAt(2));}}

For two string objects obj1 and obj2:


A) Use of obj1 == obj2 tests whether two String object references refer to the
String Co
same object
B) obj1.equals(obj2) compares the sequence of characters in obj1 and obj2.

What will be the result when you attempt to compile and run the following
code?.
public class Conv
{
public static void main(String argv[]){
Conv c=new Conv();
String s=new String("ello");
c.amethod(s);
String Co
}

public void amethod(String s){


char c='H';
c+=s;
System.out.println(c);
}
}

Examine this code:

String stringA = "Hello ";


String CoString stringB = " World";
String stringC = " Java";
String result;
Which of the following puts a reference to "Hello World Java" in result?

Consider the following code and choose the correct option:


public class Test {
String Copublic static void main(String[] args) {
String name="vikaramaditya";
System.out.println(name.codePointAt(2)+name.charAt(3)); }}
Consider the following code and choose the correct option:
public class Test {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("antarctica");
String Co
sb.reverse();
sb.replace(2, 7, "c");
sb.delete(0,2);
System.out.println(sb); }}

Which code can be inserted at Line X to print "Equal"?


public class EqTest{
public static void main(String argv[]){
EqTest e=new EqTest();
}

EqTest(){
String s="Java";
String s2="java";
String Co
// Line X
{
System.out.println("Equal");
}else
{
System.out.println("Not equal");
}
}
}

Given:
public class Theory {
public static void main(String[] args) {
String s1 = "abc";
String s2 = s1;
s1 += "d";
System.out.println(s1 + " " + s2 + " " + (s1==s2));
String Co
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.)

Consider the following code and choose the correct option:


class Test {
public static void main(String args[]) {
String name=new String("batman");
String Co
int ibegin=1;
char iend=3;
System.out.println(name.substring(ibegin, iend));
}}
Consider the following code and choose the correct option:
public class Test {
String Copublic static void main(String[] args) {
String data="78";
System.out.println(data.append("abc")); }}
Given:
String test = "This is a test";
String CoString[] tokens = test.split("\s");
System.out.println(tokens.length);
What is the result?

Consider the following code and choose the correct option:


public class Test {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("antarctica");
String Co
sb.reverse();
sb.insert(4, 'r');
sb.replace(2, 4, "c");
System.out.println(sb); }}

Consider the following code and choose the correct option:


class Test {
public static void main(String[] args) {
String Co 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] + " "); } }

What does this code write:

String CoStringTokenizer stuff = new StringTokenizer( "abc def+ghi", "+");


System.out.println( stuff.nextToken() );
System.out.println( stuff.nextToken() );

Consider the following code and choose the correct option:


class Test {
public static void main(String args[]) {
String CoString s1 = "abc";
String s2 = "def";
String s3 = s1.concat(s2.toUpperCase( ) );
System.out.println(s1+s2+s3); } }

Consider the following code and choose the correct option:


public class Test {
public static void main(String[] args) {
String Co
String name="Anthony Gomes";
int a=111;//o-111
System.out.println(name.indexOf(a)); }}
class StringManipulation{
public static void main(String[] args){
String str = new String("Cognizant");
str.concat(" Technology");
String Co
StringBuffer sbf = new StringBuffer(" Solutions");
System.out.println(str+sbf);
}}
consider the code above & select the proper output from the options.

What is the result of the following:

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


String find = "One ring to find them.";
String Co
if ( ring.startsWith("One") && find.startsWith("One") )
System.out.println( ring+find );
else
System.out.println( "Different Starts" );

Consider the following code and choose the correct option:


public class Test {
String Copublic static void main(String[] args) {
String name="Anthony Gomes";
System.out.println(name.replace('n', name.charAt(3)).compareTo(name)); }}

Consider the following code and choose the correct option:


class MyClass {
String str1="str1";
String str2 ="str2";
String CoString str3="str3";
str1.concat(str2);
System.out.println(str3.concat(str1));
}
}

Consider the following code and choose the correct option:


public class Test {
public static void main(String[] args) {
String Co
StringBuffer sb = new StringBuffer("antarctica");
sb.delete(0,6);
System.out.println(sb); }}
Consider the following code and choose the correct option:
public class Test {
String Copublic static void main(String[] args) {
String data="7882";
data+=32; System.out.println(data); }}
class X2
{
public X2 x;
public static void main(String [] args)
{
X2 x2 = new X2(); /* Line 6 */
X2 x3 = new X2(); /* Line 7 */
GarbaMe 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?

Which statement is true?


A. A class's finalize() method CANNOT be invoked explicitly.
B. super.finalize() is called implicitly by any overriding finalize() method.
C. The finalize() method for a given object is called no more than once by the
GarbaMe
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.

GarbaMeWhich of the following allows a programmer to destroy an object x?

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

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


GarbaMe
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?
Consider the following code and choose the correct option:
public class X
{
public static void main(String [] args)
{
X x = new X();
X x2 = m1(x); /* Line 6 */
GarbaMe
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?

GarbaMeHow can you force garbage collection of an object?

Which statements describe guaranteed behaviour of the garbage collection


GarbaMe
and finalization mechanisms? (Choose TWO)

Examine the following code:

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

What condition should be used so that the code prints:

12345678

Given:
public class Breaker2 {
static String o = "";
public static void main(String[] args) {
z:
for(int x = 2; x < 7; x++) {
if(x==3) continue;
ControMe
if(x==5) break z;
o = o + x;
}
System.out.println(o);
}
}
What is the result?
Consider the following code and choose the correct option:
class Test{
public static void main(String args[]){
ControMe
String hexa = "0XFF";
int number = Integer.decode(hexa);
System.out.println(number); }}

Given:
class Atom {
Atom() { System.out.print("atom "); }
}
class Rock extends Atom {
Rock(String type) { System.out.print(type); }
}
ControMepublic class Mountain extends Rock {
Mountain() {
super("granite ");
new Rock("granite ");
}
public static void main(String[] a) { new Mountain(); }
}
What is the result?

ControMeWhich of the following statements about arrays is syntactically wrong?

Given:
public class Barn {
public static void main(String[] args) {
new Barn().go("hi", 1);
new Barn().go("hi", "world", 2);
ControMe}
public void go(String... y, int x) {
System.out.print(y[y.length - 1] + " ");
}
}
What is the result?

Given:
int n = 10;
switch(n)
{
case 10: n = n + 1;
case 15: n = n + 2;
ControMe
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?
Given:
public void go() {
String o = "";
z:
for(int x = 0; x < 3; x++) {
for(int y = 0; y < 2; y++) {
if(x==1) break;
ControMe
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?

What will be the output of the program?

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++)
ControMe {
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 */
}
}
}
}

Consider the following code and choose the correct output:


class Test{
public static void main(String args[]){
ControMe int a=5;
if(a=3){
System.out.print("Three");}else{
System.out.print("Five");}}}
public void foo( boolean a, boolean b)
{
if( a )
{
System.out.println("A"); /* Line 5 */
}
else if(a && b) /* Line 7 */
{
System.out.println( "A && B");
}
else /* Line 11 */
{
ControMe
if ( !b )
{
System.out.println( "notB") ;
}
else
{
System.out.println( "ELSE" ) ;
}
}
}

What would be the result?

Consider the following code and choose the correct option:


class Test{
ControMe public static void main(String args[]){
Long l=0l;
System.out.println(l.equals(0));}}

Consider the following code and choose the correct output:


class Test{
public static void main(String args[]){
ControMe boolean flag=true;
if(flag=false){
System.out.print("TRUE");}else{
System.out.print("FALSE");}}}

class Test{
public static void main(String[] args) {
int x=-1,y=-1;
if(++x=++y)
System.out.println("R.T. Ponting");
ControMe
else
System.out.println("C.H. Gayle");
}
}
consider the code above & select the proper output from the options.
Given:
public class Batman {
int squares = 81;
public static void main(String[] args) {
new Batman().go();
}
ControMevoid go() {
incr(++squares);
System.out.println(squares);
}
void incr(int squares) { squares += 10; }
}
What is the result?

Consider the following code and choose the correct option:


class Test{
public static void main(String args[]){
ControMe
int l=7;
Long L = (Long)l;
System.out.println(L); }}

public class SwitchTest


{
public static void main(String[] args)
{
System.out.println("value =" + switchIt(4));
}
public static int switchIt(int x)
{
int j = 1;
switch (x)
{
ControMe
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?
Given:
import java.util.*;
public class Explorer3 {
public static void main(String[] args) {
TreeSet<Integer> s = new TreeSet<Integer>();
TreeSet<Integer> subs = new TreeSet<Integer>();
for(int i = 606; i < 613; i++)
ControMe
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?

Consider the code below & select the correct ouput from the options:
public class Test{
public static void main(String[] args) {
String num="";
z: for(int x=0;x<3;x++)
ControMe
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);}}

What will be the output of the program?


int x = 3;
int y = 1;
ControMeif (x = y) /* Line 3 */
{
System.out.println("x =" + x);
}

Given:
public static void test(String str) {
int check = 4;
if (check = str.length()) {
System.out.print(str.charAt(check -= 1) +", ");
} else {
System.out.print(str.charAt(0) + ", ");
ControMe
}
}
and the invocation:
test("four");
test("tee");
test("to");
What is the result?

Which collection implementation is suitable for maintaining an ordered


ControMesequence of objects,when objects are frequently inserted in and removed
from the middle of the sequence?
11. double input = 314159.26;
12. NumberFormat nf = NumberFormat.getInstance(Locale.ITALIAN);
13. String b;
ControMe
14. //insert code here

Which code, inserted at line 14, sets the value of b to 314.159,26?

int I = 0;
outer:
while (true)
{
I++;
inner:
for (int j = 0; j < 10; j++)
{
I += j;
ControMe
if (j == 3)
continue inner;
break outer;
}
continue outer;
}
System.out.println(I);

What will be thr result?

What is the range of the random number r generated by the code below?
ControMe
int r = (int)(Math.floor(Math.random() * 8)) + 2;

ControMeWhich of these statements are true?

public class While


{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
ControMe {
System.out.print("x plus one is " + (x + 1)); /* Line 8 */
}
}
}

Which statement is true?

Cosider the following code and choose the correct option:


class Test{
ControMe public static void main(String args[])
{ System.out.println(Integer.parseInt("2147483648", 10));
}}
class AutoBox {
public static void main(String args[]) {

int i = 10;
ControMe Integer iOb = 100;
i = iOb;
System.out.println(i + " " + iOb);
}
} whether this code work properly, if so what would be the result?

Consider the following code and choose the correct output:


public class Test{
public static void main(String[] args) {
int x = 0;
int y = 10;
do {
ControMe
y--;
++x;
} while (x < 5);
System.out.print(x + "," + y);
}
}

Which of the following loop bodies DOES compute the product from 1 to 10
like (1 * 2 * 3 * 4 * 5 *
6 * 7 * 8 * 9 * 10)?
int s = 1;
ControMe
for (int i = 1; i <= 10; i++)
{
<What to put here?>
}
Which of the following statements are true regarding wrapper classes?
ControMe
(Choose TWO)

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

public class Main {

public static void main(String[] args) {


TreeSet<String> tSet = new TreeSet<String>();
tSet.add("1");
ControMe
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?
What will be the output of following code?

TreeSet map = new TreeSet();


map.add("one");
map.add("two");
map.add("three");
ControMemap.add("four");
map.add("one");
Iterator it = map.iterator();
while (it.hasNext() )
{
System.out.print( it.next() + " " );
}

Consider the following code and choose the correct option:


class Test{
ControMe public static void main(String args[]){
Long data=23;
System.out.println(data); }}

ControMeWhich statements are true about maps? (Choose TWO)

Given:
public class Test {
public enum Dogs {collie, harrier, shepherd};
public static void main(String [] args) {
Dogs myDog = Dogs.shepherd;
switch (myDog) {
case collie:
System.out.print("collie ");
ControMe
case default:
System.out.print("retriever ");
case harrier:
System.out.print("harrier ");
}
}
}
What is the result?

Consider the following code and choose the correct option:


class Test{
public static void main(String args[]){
ControMe Long L = null; long l = L;
System.out.println(L);
System.out.println(l);
}}
Consider the following code and choose the correct output:
class Test{
public static void main(String args[]){
int num=3; switch(num){
ControMe
case 1: case 3: case 4: {
System.out.println("bat man"); }
case 2: case 5: {
System.out.println("spider man"); }break; } }}

ControMeWhich of the following statements is TRUE regarding a Java loop?

What is the value of ’n’ after executing the following code?


int n = 10;
int p = n + 5;
int q = p - 10;
int r = 2 * (p - q);
switch(n)
ControMe
{
case p: n = n + 1;
case q: n = n + 2;
case r: n = n + 3;
default: n = n + 4;
}

Given:
double height = 5.5;
if(height-- >= 5.0)
System.out.print("tall ");
if(--height >= 4.0)
System.out.print("average ");
ControMe
if(height-- >= 3.0)
System.out.print("short ");
else
System.out.print("very short ");
}
What would be the Result?

Consider the following code and choose the correct option:


class Test{
public static void main(String ar[]){
TreeMap<Integer,String> tree = new TreeMap<Integer,String>();
tree.put(1, "one");
tree.put(2, "two");
ControMetree.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));
}}
What is the output of the following code :
class try1{
public static void main(String[] args) {
System.out.println("good");
ControMe while(false){
System.out.println("morning");
}
}
}

Consider the following code and choose the correct output:


class Test{
public static void main(String args[]){
int num='b'; switch(num){
default :{
ControMe
System.out.print("default");}
case 100 : case 'b' : case 'c' : {
System.out.println("brownie"); break;}
case 200: case 'e': {
System.out.println("pastry"); }break; } }}

What does the following code fragment write to the monitor?

int sum = 21;


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

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

What does the code fragment prints?

what will be the result of attempting to compile and run the following class?
Public class IFTest{
public static void main(String[] args){
int i=10;
if(i==10)
ControMe
if(i<10)
System.out.println("a");
else
System.out.println("b");
}}
Given:
static void myFunc()
{
int i, s = 0;
for (int j = 0; j < 7; j++) {
i = 0;
do {
ControMe
i++;
s++;
} while (i < j);
}
System.out.println(s);
}
} What would be the result

ControMeChoose TWO correct options:

Consider the following code and choose the correct output:


class Test{
public static void main(String args[]){
int num=3; switch(num){
default :{
ControMe
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; } }}

switch(x)
{
default:
System.out.println("Hello");
}
Which of the following are acceptable types for x?
ControMe
1.byte
2.long
3.char
4.float
5.Short
6.Long
What is the output :
class One{
public static void main(String[] args) {
int a=100;
if(a>10)
ControMe System.out.println("M.S.Dhoni");
else if(a>20)
System.out.println("Sachin");
else if(a>30)
System.out.println("Virat Kohli");}
}

What is the output :


class Test{
public static void main(String[] args) {
int a=5,b=10,c=1;
if(a>c){
System.out.println("success");
ControMe
}
else{
break;
}
}
}

Consider the following code and choose the correct option:


class Test{
public static void main(String args[]){ int x=034;
ControMe int y=12;
int ans=x+y;
System.out.println(ans);
}}

Given:
public class Test {
public enum Dogs {collie, harrier};
public static void main(String [] args) {
Dogs myDog = Dogs.collie;
switch (myDog) {
case collie:
ControMe
System.out.print("collie ");
case harrier:
System.out.print("harrier ");
}
}
}
What is the result?
What will be the output of following code?

import java.util.*;
class I
{
public static void main (String[] args)
ControMe {
Object i = new ArrayList().iterator();
System.out.print((i instanceof List)+",");
System.out.print((i instanceof Iterator)+",");
System.out.print(i instanceof ListIterator);
}
}

public class Test {


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

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


ControMe
System.out.print("1 ");
System.out.print("2 ");
if ((b2 = true) && b1 )
System.out.print("3 ");
}
}
What is the result?

Given:
int a = 5;
int b = 5;
int c = 5;
if (a > 3)
if (b > 4)
if (c > 5)
ControMe
c += 1;
else
c += 2;
else
c += 3;
c += 4;
What is the value of variable c after executing the following code?
Given:
Float pi = new Float(3.14f);
if (pi > 3) {
System.out.print("pi is bigger than 3. ");
}
else {
ControMe
System.out.print("pi is not bigger than 3. ");
}
finally {
System.out.println("Have a nice day.");
}
What is the result?

Consider the following code and choose the correct option:


int i = l, j = -1;
switch (i)
{
ControMe case 0, 1: j = 1;
case 2: j = 2;
default: j = 0;
}
System.out.println("j = " + j);

What is the output :


class try1{
public static void main(String[] args) {
int x=1;
if(x--)
ControMe
System.out.println("good");
else
System.out.println("bad");
}
}

Given:
int x = 0;
int y = 10;
do {
ControMey--;
++x;
} while (x < 5);
System.out.print(x + "," + y);
What is the result?
What are the thing to be placed to complete the code?
class Wrap {
public static void main(String args[]) {

_______________ iOb = ___________ Integer(100);


ControMe
int i = iOb.intValue();

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


}
}

Introd MeWhich of the following options give the valid package names? (Choose 3)

Introd MeThe term 'Java Platform' refers to ________________.

Introd MeWhich of the following statement gives the use of CLASSPATH?

Which of the following options give the valid argument types for main()
Introd Me
method? (Choose 2)

Introd MeWhich of the following are true about packages? (Choose 2)

Which of the following statements are true regarding java.lang.Object class?


Introd Me
(Choose 2)

Which of the following option gives one possible use of the statement 'the
Introd Me
name of the public class should match with its file name'?

Consider the following code and choose the correct option:


class Cthread extends Thread{
Cthread(){start();}
public void run(){
Threa Si System.out.print("Hi");}
public static void main (String args[]){
Cthread th1=new Cthread();
Cthread th2=new Cthread();
}}

public class MyRunnable implements Runnable


{
public void run()
{
Threa Si
// some code here
}
}
which of these will create and start this thread?
Consider the following code and choose the correct option:
class Nthread extends Thread{
public void run(){
System.out.print("Hi");}
Threa Si
public static void main(String args[]){
Nthread th1=new Nthread();
Nthread th2=new Nthread();
}

Consider the following code and choose the correct option:


class Cthread extends Thread{
public void run(){
System.out.print("Hi");}
public static void main (String args[]){
Threa Si
Cthread th1=new Cthread();
th1.run();
th1.start();
th1.run();
}}

The following block of code creates a Thread using a Runnable target:

Runnable target = new MyRunnable();


Threa MeThread myThread = new Thread(target);

Which of the following classes can be used to create the target, so that the
preceding code compiles correctly?
What will be the output of the program?

class MyThread extends Thread


{
MyThread() {}
MyThread(Runnable r) {super(r); }
public void run()
{
System.out.print("Inside Thread ");
}
}
class MyRunnable implements Runnable
{
Threa Me
public void run()
{
System.out.print(" Inside Runnable");
}
}
class Test
{
public static void main(String[] args)
{
new MyThread().start();
new MyThread(new MyRunnable()).start();
}
}

Threa MeWhich of the following methods are defined in class Thread? (Choose TWO)
Threa Si wait(), notify() and notifyAll() methods belong to ________
Consider the following code and choose the correct option:
class A implements Runnable{ int k;
public void run(){
Threa Si k++; }
public static void main(String args[]){
A a1=new A();
a1.run();}

class Cthread extends Thread{


public void run(){
System.out.print("Hi");}
public static void main (String args[]){
Threa Si Cthread th1=new Cthread();
th1.run();
th1.start();
th1.start();
}}
What will be the output of the program?

class MyThread extends Thread


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

class PingPong2 {
synchronized void hit(long n) {
for(int i = 1; i < 3; i++)
System.out.print(n + "-" + i + " ");
}
}
public class Tester implements Runnable {
Threa Si 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?

Given:
public class Threads4 {
public static void main (String[] args) {
new Threads4().go();
}
public void go() {
Runnable r = new Runnable() {
public void run() {
Threa Si System.out.print("run");
}
};
Thread t = new Thread(r);
t.start();
t.start();
}
}
What is the result?
A) Multiple processes share same memory location
B) Switching from one thread to another is easier than switching from one
Threa Si process to another
C) Thread makes it possible to maximize resource utilization
D) Process is a light weight program

Threa Si Which of the following methods registers a thread in a thread scheduler?

Which of the following statements can be used to create a new Thread?


Threa Si
(Choose TWO)

class Thread2 {
public static void main(String[] args) {
new Thread2().go(); }
public void go(){
Runnable rn=new Runnable(){
Threa Si 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?

Assume the following method is properly synchronized and called from a


thread A on an object B:

Threa Si wait(2000);

After calling this method, when will the thread A become a candidate to get
another turn at the CPU?
A) Exception is the superclass of all errors and exceptions in the java
Threa Si language
B) RuntimeException and its subclasses are unchecked exception.
Select the variable which are in java.lang.annotation.RetentionPolicy class.
Annot Si
(Choose THREE)
Annot Si Custom annotations can be created using
Annot Si Choose the meta annotations. (Choose THREE)
All annotation types should maually extend the Annotation interface. State
Annot Si
TRUE/FALSE
If no retention policy is specified for an annotation, then the default policy of
Annot Si
__________ is used.
Annot Si Select the Uses of annotations. (Choose THREE)
Intro Si Which of the following is not an attribute of object?
Intro Si What is the advantage of runtime polymorphism?
Intro Si Which of the following is an example of IS A relationship?
Intro Si Which of following set of functions are example of method overloading
Intro Si Which of the following is not a valid relation between classes?
ExceptSi Choose the correct option:

consider the code & choose the correct output:


class Threads2 implements Runnable {

public void run() {


System.out.println("run.");
throw new RuntimeException("Problem");
ExceptSi }
public static void main(String[] args) {
Thread t = new Thread(new Threads2());
t.start();
System.out.println("End of method.");
}
}

Consider the following code:

System.out.print("Start ");
try
{
System.out.print("Hello world");
throw new FileNotFoundException();
}
System.out.print(" Catch Here "); /* Line 7 */
catch(EOFException e)
ExceptCo{
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.

Given:
public class ExceptionTest
{
class TestException extends Exception {}
public void runTest() throws TestException {}
ExceptSi public void test() /* Line X */
{
runTest();
}
}
At Line X, which code is necessary to make the code compile?
Consider the following code and choose the correct option:
class Test{
public static void parse(String str) {
try { int num = Integer.parseInt(str);
ExceptCo
} catch (NumberFormatException nfe) {
num = 0; } finally { System.out.println(num);
} } public static void main(String[] args) {
parse("one"); }

ExceptSi Which of the following statements is true?

class Trial{
public static void main(String[] args){
try{
System.out.println("One");
int y = 2 / 0;
System.out.println("Two");
}
ExceptSi
catch(RuntimeException ex){
System.out.println("Catch");
}
finally{
System.out.println("Finally");
}
}}

State True or False:


ExceptCoThe main() method of a program can declare that it throws checked
exception.

Given:
static void test() {
try {
String x = null;
System.out.print(x.toString() + " ");
}
ExceptSi finally { System.out.print("finally "); }
}
public static void main(String[] args) {
try { test(); }
catch (Exception ex) { System.out.print("exception "); }
}
What is the result?

ExceptSi Which statement is true?

ExceptSi Which of the following is a checked exception?


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

Given the following program,which statements is true?


Public class Exception {
public static void main(String[] args) {
try {
ExceptSi if(args.length == 0) return;
System.out.println(args[0]);
}finally {
System.out.println("The end");
}}}

Consider the following code and choose the correct option:


ExceptSi int array[] = new int[10];
array[-1] = 0;

class PropagateException{
public static void main(String[] args){
try{
method();
System.out.println("method() called");
}
catch(ArithmeticException ex){
System.out.println("Arithmetic Exception");
ExceptSi
}
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.

ExceptSi Which statement is true?


What is wrong with the following code?

Class MyException extends Exception{}


public class Test{
public void foo() {
try {
bar();
} finally {
baz();
ExceptCo
} catch(MyException e) {}
}
public void bar() throws MyException {
throw new MyException();
}
public void baz() throws RuntimeException {
throw new RuntimeException();
}
}

The exceptions for which the compiler doesn’t enforce the handle or declare
ExceptSi
rule

Consider the following code and choose the correct option:


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

class X implements Runnable


{
public static void main(String args[])
{
ExceptSi /* Missing code? */
}
public void run() {}
}
Which of the following line of code is suitable to start a thread ?

ExceptSi Which two can be used to create a new Thread?


Which four can be thrown using the throw statement?

1.Error
2.Event
ExceptSi
3.Object
4.Throwable
5.Exception
6.RuntimeException

Which of the following statements regarding static methods are correct? (2


ExceptSi
answers)

In the given code snippet


try { int a = Integer.parseInt("one"); }
what is used to create an appropriate catch block? (Choose all that apply.)
ExceptSi A. ClassCastException
B. IllegalStateException
C. NumberFormatException
D. IllegalArgumentException

ExceptSi Which of the following methods are static?


class Trial{
public static void main(String[] args){
try{
System.out.println("Try Block");
ExceptSi }
finally{
System.out.println("Finally Block");
}
}}

class Animal { public String noise() { return "peep"; } }


class Dog extends Animal {
public String noise() { return "bark"; }
}
class Cat extends Animal {
public String noise() { return "meow"; }
}
ExceptSi
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.
Consider the following code and choose the correct option:
class Test{
static void display(){
throw new RuntimeException();
} public static void main(String args[]){
ExceptSi
try{ display(); }catch(Exception e){
throw new NullPointerException();}
finally{try{ display();
}catch(NullPointerException e){ System.out.println("caught");}
System.out.println("exit");}}}

Consider the following code and choose the correct option:


class Test{
static void test() throws RuntimeException {
try { System.out.print("test ");
ExceptCo 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"); } }

class Test{
public static void main(String[] args){
try{
Integer.parseInt("1.0");
}
catch(Exception e){
ExceptSi System.out.println("Exception occurred");
}
catch(RuntimeException ex){
System.out.println("RuntimeException");
}
}}
consider the code above & select the proper output from the options.

ExceptSi Which of the following statements are true? (Choose TWO)


class s implements Runnable
{
int x, y;
public void run()
{
for(int i = 0; i < 1000; i++)
synchronized(this)
{
x = 12;
y = 12;
}
ExceptCo
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?

Which can appropriately be thrown by a programmer using Java SE


ExceptSi technology to create
a desktop application?
What is the keyword to use when the access of a method has to be restricted
ExceptSi
to only one thread at a time
What will be the output of the program?

public class RTExcept


{
public static void throwit ()
{
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args)
{
try
{
ExceptSi System.out.print("hello ");
throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
}
System.out.println("after ");
}
}

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

Consider the following code and choose the correct option:


class Test{
static void display(){
throw new RuntimeException();
}
ExceptSi
public static void main(String args[]){
try{display();
}catch(Exception e){ }
catch(RuntimeException re){}
finally{System.out.println("exit");}}}
A) Checked Exception must be explicity caught or propagated to the calling
method
ExceptSi 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.

public class MyProgram


{
public static void throwit()
{
throw new RuntimeException();
}
public static void main(String args[])
{
try
{
ExceptCo System.out.println("Hello world ");
throwit();
System.out.println("Done with try block ");
}
finally
{
System.out.println("Finally executing ");
}
}
}
which answer most closely indicates the behavior of the program?

If a method is capable of causing an exception that it does not handle, it must


ExceptSi specify this behavior using throws so that callers of the method can guard
themselves against such Exception
class Trial{
public static void main(String[] args){
ExceptSi try{
System.out.println("Java is portable");
}}}

public static void parse(String str) {


try {
float f = Float.parseFloat(str);
} catch (NumberFormatException nfe) {
f = 0;
} finally {
ExceptCo
System.out.println(f);
}
}
public static void main(String[] args) {
parse("invalid");
}
Which digit,and in what order,will be printed when the following program is
run?

Public class MyClass {


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

Given:
public class TestSeven extends Thread {
private static int x;
public synchronized void doThings() {
int current = x;
current++;
ExceptSi x = current;
}
public void run() {
doThings();
}
}
Which statement is true?

Which of the following statements is/are true?


Statement 1: Writing finally block is optional.
ExceptSi
Statement 2: When no exception occurs then complete try block and finally
block will execute but no catch block will execute.  
Given:
class X implements Runnable
{
public static void main(String args[])
{
ExceptSi
/* Some code */
}
public void run() {}
}
Which of the following line of code is suitable to start a thread ?

Given:
class X { public void foo() { System.out.print("X "); } }

public class SubB extends X {


public void foo() throws RuntimeException {
super.foo();
if (true) throw new RuntimeException();
ExceptSi
System.out.print("B ");
}
public static void main(String[] args) {
new SubB().foo();
}
}
What is the result?

Which three of the following are methods of the Object class?

1.notify();
2.notifyAll();
3.isInterrupted();
ExceptSi
4.synchronized();
5.interrupt();
6.wait(long msecs);
7.sleep(long msecs);
8.yield();
public class RTExcept
{
public static void throwit ()
{
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args)
{
try
{
System.out.print("hello ");
ExceptCo throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
}
System.out.println("after ");
}
}

What will happen when you attempt to compile and run the following code?
public class Bground extends Thread{
public static void main(String argv[]){
Bground b = new Bground();
b.run();
}
ExceptSi
public void start(){
for (int i = 0; i <10; i++){
System.out.println("Value of i = " + i);
}
}
}
Given two programs:
1. package pkgA;
2. public class Abc {
3. int a = 5;
4. protected int b = 6;
5. public int c = 7;
6. }

3. package pkgB;
ExceptCo4. 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)

What will the output of following code?

try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
ExceptSi
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");

Given:
11. class A {
12. public void process() { System.out.print("A,"); }
13. class B extends A {
14. public void process() throws IOException {
15. super.process();
16. System.out.print("B,");
ExceptSi
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?
Consider the following code and choose the correct option:
public class Test {
public static void main(String[] args) {
File file=new File("D:/jlist.lst");
byte buffer[]=new byte[(int)file.length()+1];
IO OpMe
FileInputStream fis=new FileInputStream(file);
fis.read(buffer);
System.out.println(buffer);
}
}

Consider the following code and choose the correct option:


public class Test {
public static void main(String[] args) throws IOException {
File file=new File("D:/jlist.lst");
IO OpMe 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); } }}

import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class MoreEndings {
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream("seq.txt");
InputStreamReader isr = new InputStreamReader(fis);
int i = isr.read();
while (i != -1) {
System.out.print((char)i + "|");
IO OpMei = 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?
Consider the following code and choose the correct output:
public class Person{
public void talk(){ System.out.print("I am a Person "); }
}
public class Student extends Person {
public void talk(){ System.out.print("I am a Student "); }
}
IO OpMe
what is the result of this piece of code:
public class Test{
public static void main(String args[]){
Person p = new Student();
p.talk();
}
}

Consider the following code and choose the correct option:


public class Test{
public static void main(String[] args) throws IOException {
File file = new File("d:/temp.txt");
IO OpMe
FileReader reader=new FileReader(file);
reader.skip(7); int ch;
while((ch=reader.read())!=-1){
System.out.print((char)ch); } }}

Consider the following code and choose the correct option:


public class Test {
public static void main(String[] args) throws IOException {
File file=new File("D:/jlist.lst");
IO OpMe
byte buffer[]=new byte[(int)file.length()+1];
FileInputStream fis=new FileInputStream(file);
fis.read(buffer);
System.out.println(new String(buffer)); }}

Which of these are two legal ways of accessing a File named "file.tst" for
reading. Select the correct option:
A)FileReader fr = new FileReader("file.tst");
IO OpMe
B)FileInputStream fr = new FileInputStream("file.tst");
C)InputStreamReader isr = new InputStreamReader(fr, "UTF8");
D)FileReader fr = new FileReader("file.tst", "UTF8");

Consider the following code and choose the correct option:


class std{
int call; std(int c){call=c;}
int getCall(){return call;}
}
public class Test{
public static void main(String[] args) throws IOException {
IO OpMe
File file=new File("d:/std.txt");
FileOutputStream fos=new FileOutputStream(file);
ObjectOutputStream oos=new ObjectOutputStream(fos);
std s1=new std(10);
oos.writeObject(s1);
oos.close();
}}
Consider the following code and choose the correct option:
public class Test {
public static void main(String[] args) throws IOException {
File file=new File("D:/jlist.lst");
IO OpMe 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); } }}

What happens when the constructor for FileInputStream fails to open a file for
IO OpMe
reading?

import java.io.*;
public class MyClass implements Serializable {

private Tree tree = new Tree();

public static void main(String [] args) {


IO OpMeMyClass 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(); }
}}

What is the DataOutputStream method that writes double precision floating


IO OpMe
point values to a stream?

Which of the following opens the file "myData.stuff" for output first deleting
IO OpMe
any file with that name?

A file is readable but not writable on the file system of the host platform. What
will
IO OpMe
be the result of calling the method canWrite() on a File object representing
this file?

Consider the following code and choose the correct option:


public class Test{
public static void main(String[] args) {
File dir = new File("dir");
IO OpMe dir.mkdir();
File f1 = new File(dir, "f1.txt"); try {
f1.createNewFile(); } catch (IOException e) { ; }
File newDir = new File("newDir");
dir.renameTo(newDir);} }
Consider the following code and choose the correct option:
public class Test {
public static void main(String[] args) throws IOException {
String data="Confidential info";
IO OpMe
byte buffer[]=data.getBytes();
FileOutputStream fos=new FileOutputStream("d:/temp");
for(byte d : buffer){
fos.write(d); } }}

Consider the following code and choose the correct option:


public class Test {
IO OpMepublic static void main(String[] args) {
File file=new File("d:/prj,d:/lib");
file.mkdirs();}}

Consider the following code and choose the correct option:


public class Test {
public static void main(String[] args) throws IOException {
File file=new File("d:/data");
IO OpMe 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));}}

Consider the following code and choose the correct option:


class std implements Serializable{
int call; std(int c){call=c;}
int getCall(){return call;}
}
public class Test{
public static void main(String[] args) throws IOException {
IO OpMe
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();
}}
Given :
import java.io.*;
public class ReadingFor {
public static void main(String[] args) {
String s;
try {
FileReader fr = new FileReader("myfile.txt");
BufferedReader br = new BufferedReader(fr);
while((s = br.readLine()) != null)
IO OpMe
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?

Consider the following code and choose the correct option:


public class Test {
IO OpMepublic static void main(String[] args) {
File file=new File("d:/prj/lib");
file.mkdirs();}}

import java.io.*;
public class MyClass implements Serializable {
private int a;
public int getA() { return a; }
publicMyClass(int a){this.a=a; }
private void writeObject( ObjectOutputStream s)
IO OpMethrows IOException {
// insert code here
}
}

Which code fragment, inserted at line 15, will allow Foo objects to be
correctly serialized and deserialized?

A) It is not possible to execute select query with execute() method


JDBC Si
B) CallableStatement can executes store procedures only but not functions

A) When one use callablestatement, in that case only parameters are send
JDBC Meover network not sql query.
B) In preparestatement sql query will compile for first time only
JDBC Si getConnection() is method available in?

Sylvy wants to develop Student management system, which requires


JDBC Mefrequent insert operation about student details. In order to insert student
record which statement interface will give good performance

Which method will return boolean when we try to execute SQL Query from a
JDBC Si
JDBC program?
An application can connect to different Databases at the same time. State
JDBC Si
TRUE/FALSE.
A) By default, all JDBC transactions are auto commit
B) PreparedStatement suitable for dynamic sql and requires one time
JDBC Si
compilation
C) with JDBC it is possible to fetch information about the database

JDBC Si how to register driver class in the memory?

JDBC Si What is the use of wasNull() in ResultSet interface?

JDBC Si Which of the following options contains only JDBC interfaces?

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

JDBC Si By default all JDBC transactions are autocommit. State TRUE/FALSE.


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

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

rs.close();
// somecode
} What should be imported related to ResultSet?

Consider the following code & select the correct option for output.
String sql ="select empno,ename from emp";
PreparedStatement pst=cn.prepareStatement(sql);
JDBC Me
System.out.println(pst.toString());
ResultSet rs=pst.executeQuery();
System.out.println(rs.getString(1)+ " "+rs.getString(2));
JDBC Si What is the default type of ResultSet in JDBC applications?

Consider the code below & select the correct ouput from the options:

String sql ="select * from ?";


String table=" txyz ";
JDBC Me PreparedStatement pst=cn.prepareStatement(sql);
pst.setString(1,table );
ResultSet rs=pst.executeQuery();
while(rs.next()){
System.out.println(rs.getString(1)); }

Cosider the following code & select the correct output.


String sql ="select rollno, name from student";
PreparedStatement pst=cn.prepareStatement(sql);
JDBC Me System.out.println(pst.toString());
ResultSet rs=pst.executeQuery();
while(rs.next()){
System.out.println(rs.getString(3)); }

Given :
public class MoreEndings {
public static void main(String[] args) throws Exception {
JDBC Si Class driverClass = Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
DriverManager.registerDriver((Driver) driverClass.newInstance());
// Some code
} Inorder to compile & execute this code, what should we import?

Which of the following methods finds the maximum number of connections


JDBC Si
that a specific driver can obtain?
Which of the following method can be used to execute to execute all type of
JDBC Si
queries i.e. either Selection or Updation SQL Queries?
It is possible to insert/update record in a table by using ResultSet. State
JDBC Si
TRUE/FALSE
Which of the following methods are needed for loading a database driver in
JDBC Si
JDBC?
Carefully read the question and answer accordingly.
AccessMe________ determines which member of a class can be used by other
classes.

Carefully read the question and answer accordingly.


A class can be declared as _______ if you do not want the class to be
AccessMe
subclassed. Using
the __________keyword we can abstract a class from its implementation

Carefully read the question and answer accordingly.


What will be the output for following code?
class Super
{
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;
}
AccessMe
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);
o.Show();
}
}
Carefully read the question and answer accordingly.
What will be the output for following code?
public class Variables
{
public static void main(String[]args)
AccessMe
{
public int i=10;
System.out.println(i++);
}
}

Carefully read the question and answer accordingly.


AccessMe
The constructor of a class must not have a return type.

Carefully read the question and answer accordingly.


When one method is overridden in sub class the access specifier of the
AccessMe
method in sub class should be equal as method in super class.
State True or False.

Carefully read the question and answer accordingly.


AccessMeWhich of the following method is used to initialize the instance variable of a
class.

Carefully read the question and answer accordingly.


AccessMeIf display method in super class has a protected specifier then what should
be the specifier for the overriding display method in sub class?

Carefully read the question and answer accordingly.


What will be the output for following code?
class Super
{
static void show()
{
System.out.println("super class show method");
}
static class StaticMethods
{
AccessMevoid show()
{
System.out.println("sub class show method");
}
}
public static void main(String[]args)
{
Super.show();
new Super.StaticMethods().show();
}
}
Carefully read the question and answer 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
AccessMe
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

Carefully read the question and answer accordingly.


AccessMeA field with default access specifier can be accessed out side the package.
State True or False.

Carefully read the question and answer accordingly.


AccessMe
Which of the following are true about protected access specifier?

Carefully read the question and answer accordingly.


What will be the output of following code?
class Super2
{
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
AccessMe{
public void display()
{

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


}

public static void main(String [] args)


{

InheritMethod o=new InheritMethod();

o.exe();
}

}
Carefully read the question and answer accordingly.
AccessMe
Which of the following are true about constructors?

Carefully read the question and answer accordingly.


AccessMeConstructor of an class is executed each time when an object of that class is
created

Carefully read the question and answer 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;
}
}
Inheri Co
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 accordingly.


public interface Status
{
/* insert code here */ int MY_VALUE = 10;
}
Inheri Co
Which are valid on commented line?
1.final
2.static
3.native
4.public
Carefully read the question and answer accordingly.
What is the outputof below code:
package p1;
class Parent {
public static void doWork() {
System.out.println("Parent");
}
}
class Child extends Parent {
Inheri Co
public static void doWork() {
System.out.println("Child");
}
}
class Test {
public static void main(String[] args) {
Child.doWork();
}
}

Carefully read the question and answer accordingly.


abstract public class Employee
{
protected abstract double getSalesAmount();
public double getCommision() {
return getSalesAmount() * 0.15;
}
}
class Sales extends Employee
Inheri Me
{
// 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; }

Carefully read the question and answer accordingly.


State whether TRUE or FALSE.
Inheri Me
Object class provides a method named getClass() which returns runtime
class of an object.
Carefully read the question and answer accordingly.
State whether TRUE or FALSE.
Inheri Me
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 accordingly.
Inheri MeWhich of the following keywords ensures that a method cannot be
overridden?
Carefully read the question and answer accordingly.
public class Client1
{
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
Inheri Co
{
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?

Carefully read the question and answer 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();
}
}
Inheri Co
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 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);
Inheri Me
}
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();
}
}

Carefully read the question and answer accordingly.


State whether TRUE or FALSE.
Inheri Me
An overriding method can also return a subtype of the type returned by the
overridden method.
Carefully read the question and answer accordingly.
Inheri MeState whether TRUE or FALSE.
An abstract class cannot contain non abstract methods

Carefully read the question and answer accordingly.


Inheri MeState whether TRUE or FALSE.
The super() call can only be used in constructor calls and not method calls.
Carefully read the question and answer 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();
}
Inheri Coclass 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 accordingly.


State whether TRUE or FALSE.
Inheri Me
If any class has at least one abstract method you must declare it as abstract
class
Carefully read the question and answer accordingly.
State whether TRUE or FALSE.
Inheri Me
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 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;
Inheri Co 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.22F));
}
}

Carefully read the question and answer accordingly.


interface B
{
public void bM1();
public void bM2();
}
abstract class A implements B
{
Inheri Co
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?
Carefully read the question and answer accordingly.
interface A
{
public abstract void aM1();
public abstract void aM2();
}
interface B extends A
Inheri Co{
public void bM1();
public void bM2();
}
public class Demo extends Object implements B
{
}
In above scenario class Demo must override which methods?

Carefully read the question and answer accordingly.


What is the output of below code:
package p1;
public class Test {
public static void main(String[] args) {
Test t1 = new Test();
Inheri Co 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");
}
}

Carefully read the question and answer accordingly.


Choose the correct option.
Statement I: When an abstract class is sub classed, the subclass should
Inheri Co
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.

Carefully read the question and answer accordingly.


State whether TRUE or FALSE.
Inheri Me
Interface can be used when common functionalities have to be implemented
differently across multiple classes.
Carefully read the question and answer accordingly.
Choose the correct option.
Statement I: When all methods in a class are abstract the class can be
Inheri Medeclared as an interface.
Choose the correct option.
Statement II: An interface defines a contract for classes to implement the
behavior.
Carefully read the question and answer accordingly.
What is the outputof below code:
package p1;
abstract class LivingThings{
public abstract int walk();
}
class Human extends LivingThings{
@Override
Inheri Copublic 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 accordingly.


abstract class Vehicle
{
public int speed()
{
return 0;
}
}
class Car extends Vehicle
{
public int speed()
{
return 60;
}
}
class RaceCar extends Car
Inheri Co{
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());
}
}
What is the result?
Carefully read the question and answer accordingly.
What will be the output of following code?
class InterfaceDemo
{
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
}
Inheri Co
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");
}
}

Carefully read the question and answer accordingly.


public class Person
{
private String name;
public Person(String name) { this.name = name; }
Inheri Mepublic boolean equals(Person p)
{
return p.name.equals(this.name);
}
}
Which statement is true?

Carefully read the question and answer accordingly.


Abstract classes can be used when
Inheri CoStatement I: Some implemented functionalities are common between classes
Statement II: Some functionalities need to be implemented in sub classes
that extends the abstract class
Carefully read the question and answer 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{
Inheri Co
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 accordingly.


Inheri MeWhich of the following correctly fits for the definition 'holding instances of
other objects'?

Carefully read the question and answer accordingly.


What will be the output for following code
public class
MethodOverloading {
int m=10,n;
public void div(int a) throws Exception{
n=m/a;
System.out.println(n);
}
Inheri Me
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);
}
}
Carefully read the question and answer accordingly.
class InterfaceDemo
{
public static void main(String [] args)
{
DigiCam cam1=new DigiCam();
cam1.doCharge();
}//main
}
interface USB
{
Inheri Co
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?

Carefully read the question and answer accordingly.


Choose the correct option.
Statement I: A subclass inherits all of the “public” and “protected” members of
Inheri Me
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.
Carefully read the question and answer 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?
Inheri Co1.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 */}
}

Carefully read the question and answer accordingly.


Keywor
MeWhich of the following is the correct syntax for suggesting that the JVM to
performs garbage collection?
Carefully read the question and answer accordingly.
Which of the following code snippets make objects eligible for Garbage
Collection?
Keywor
Me
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;

Carefully read the question and answer 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");
Keywor
Me
line 2. String str1=str;
line 3.str=new String("Hi");
line 4.str1=new String("Hello Again");
5.return;
}
}
Carefully read the question and answer accordingly.
Statement A:finalize will always run before an object is garbage collected
Keywor
Me
Statement B:finalize method will be called only once by the garbage collector
which of the following is true?

Carefully read the question and answer accordingly.


How can you force garbage collection of an object?
1.Garbage collection cannot be forced
Keywor
Me
2.Call System.gc().
3.Call Runtime.gc().
4. Set all references to the object to new values(null, for example).
Carefully read the question and answer accordingly.
Keywor
Me
Members of the classs are accessed by _________ operator

Carefully read the question and answer accordingly.


What will be the output for following code?
public class VariableDec1
{
public static void main(String[]args)
{
Keywor
Me
int I=32;
char c=65;
char a=c+I;
System.out.println(a);
}
}

Carefully read the question and answer accordingly.


What will be the output for following code?
public class Variabledec {
public static void main(String[]args){
boolean x = true;
Keywor
Meint a;
if(x) a = x ? 2: 1;
else a = x ? 3: 4;
System.out.println(a);
}
}

Carefully read the question and answer accordingly.


Keywor
MeGarbage collector thread is a daemon thread.
State True or False.
Carefully read the question and answer accordingly.
Keywor
Me
Find the keyword which is not used to implement exception
Carefully read the question and answer accordingly.
Keywor
Me
The ++ operator postfix and prefix has the same effect
Carefully read the question and answer accordingly.
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)
Keywor
Me {
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;
}
}
}

Carefully read the question and answer accordingly.


Keywor
MeGarbage collection guarantee that a program will not run out of memory.
State True or False.

Carefully read the question and answer accordingly.


What will be the output for following code?
public class Operators
{
public static void main(String[]args)
{
int i=12;
Keywor
Me
int j=13;
int k=++i-j--;
System.out.println(i);
System.out.println(j);
System.out.println(k);
}
}

Carefully read the question and answer accordingly.


Keywor
Me
Which of the following is not the Java keyword?
Carefully read the question and answer accordingly.
Keywor
Me
_____________ Operator is used to create an object.
Carefully read the question and answer accordingly.
What is the correct structure of a java program?
I: import statement
Keywor
Me
II: class declaration
III: package statement
IV: method,variable declarations
Carefully read the question and answer accordingly.
public class Threads
{
public static void main (String[] args)
{
new Threads().go();
}
public void go()
{
Runnable r = new Runnable()
{
ThreadMe public void run()
{
System.out.print("Run");
}
};

Thread t = new Thread(r);


t.start();
t.start();
}
}
What will be the result?

Carefully read the question and answer accordingly.


State whether TRUE or FALSE.
ThreadMe
Threads are small process which run in shared memory space within a
process.

Carefully read the question and answer accordingly.


Predict the output of below code:
package p1;
class MyThread extends Thread {
public void run(int a) {
System.out.println("Important job running in MyThread");
}
public void run(String s) {
ThreadMe System.out.println("String in run");
}
}
class Test {
public static void main(String[] args) {
MyThread t1=new MyThread();
t1.start();
}
}
Carefully read the question and answer accordingly.
What will be the output of below code:
package p1;
class MyThread extends Thread {
public void run() {
System.out.println("Important job running in MyThread");
}
ThreadMe
}
class Test {
public static void main(String[] args) {
MyThread t1=new MyThread();
t1.run();
}
}

Carefully read the question and answer accordingly.


class Background implements Runnable{
int i = 0;
public int run(){
while (true) {
ThreadMei++;
System.out.println("i="+i);
}
return 1;
}
}//End class

Carefully read the question and answer accordingly.


Which of the following statements are true?
Statement1: When a thread is sleeping as a result of sleep(), it releases its
ThreadMe
locks.
Statement2: The Object.wait() method can be invoked only from a
synchronized context.

Carefully read the question and answer 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) {
ThreadMe
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 accordingly.
public class TestDemo implements Runnable
{
public void run()
{
System.out.print("Runner");
}
public static void main(String[] args)
ThreadMe
{
Thread t = new Thread(new TestDemo());
t.run();
t.run();
t.start();
}
}
What will be the result?

Carefully read the question and answer accordingly.


You have created a TimeOut class as an extension of Thread, the purpose of
which is to print a “Time’s Over” message if the Thread is not interrupted
within 10 seconds of being started. Here is the run method that you have
coded:
public void run() {
System.out.println(“Start!”);
ThreadMetry {
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?

Carefully read the question and answer accordingly.


ThreadMe
Which of the below is invalid state of thread?

Carefully read the question and answer 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.
ThreadMe
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().

Carefully read the question and answer accordingly.


ThreadMe
Which of these is not valid method in Thread class
Carefully read the question and answer accordingly.
ThreadMe
Java provides ____ ways to create Threads.
Carefully read the question and answer accordingly.
ThreadMe
Inter thread communication is achieved using which of the below methods?

Carefully read the question and answer accordingly.


### Me
Synchronization is achieved by using which of the below methods
Carefully read the question and answer accordingly.
ThreadMe
Which of these is not a benefit of Multithreading?

Carefully read the question and answer accordingly.


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();
CollecCo
l.add(20);
l.add("abc");
l.add(30);
c.addAll(l);
c.removeAll(l);
System.out.println( c );
}
}

Carefully read the question and answer accordingly.


Which of the following are not List implementations?
1.Vector
CollecMe
2.Hashtable
3.LinkedList
4.Properties

Carefully read the question and answer accordingly.


CollecCo
Which of these interface(s) are part of Java’s core collection framework?

Carefully read the question and answer accordingly.


CollecMe
foreach loop is the only option to iterate over a Map

Carefully read the question and answer accordingly.


Consider the following code:
01 import java.util.Set;
02 import java.util.TreeSet;
03
04 class TestSet {
05 public static void main(String[] args) {
CollecCo06 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?
Carefully read the question and answer accordingly.
CollecCo
LinkedList represents a collection that does not allow duplicate elements.

Carefully read the question and answer accordingly.


CollecCoUnder  java.util package we have "Collections" as Class and "Collection" as
Interface 
Carefully read the question and answer accordingly.
CollecMe
What is the return type of next() in Iterator?

Carefully read the question and answer accordingly.


Consider the following partial code:
CollecMe
java.util.Date date = new java.util.Date();
Which of the following statement is true regarding the above partial code?

Carefully read the question and answer accordingly.


CollecCo
Which of the following are true statements?

Carefully read the question and answer accordingly.


What is the data type of m in the following code?
import java.util.*;
public class set1
{
public static void main(String [] args)
{
CollecCo
Set s=new HashSet();
s.add(20);
s.add("abc");
for( _____ m:s)
System.out.println(m);
}
}

Carefully read the question and answer accordingly.


CollecCoEnumeration is having remove() method.
State True or False.

Carefully read the question and answer accordingly.


CollecCo
The add method of Set returns false if you try to add a duplicate element.

Carefully read the question and answer accordingly.


As per the below code find which statements are true.
public class Test {
public static void main(String[] args) {
Line 1: ArrayList<String> myList=new List<String>();
CollecMe Line 2: String string = new String();
Line 3: myList.add("string");
Line 4: int index = myList.indexOf("string");
System.out.println(index);
}
}
Carefully read the question and answer accordingly.
State TRUE or FALSE.
line 1: public class Test {
line 2: public static void main(String[] args) {
line 3: Queue queue = new LinkedList();
CollecMeline 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 accordingly.


CollecMe
The LinkedList class supports two constructors.
Carefully read the question and answer accordingly.
CollecCo
Which of these are interfaces in the collection framework

Carefully read the question and answer accordingly.


CollecMe
Which collection class allows you to associate its elements with key values

Carefully read the question and answer accordingly.


CollecCo
TreeSet uses which two interfaces to sort the data
Carefully read the question and answer accordingly.
CollecMeIterator i= new HashMap().entrySet().iterator();
is this correct declaration

Carefully read the question and answer accordingly.


CollecCo
Which statement are true for the class HashSet?

Carefully read the question and answer accordingly.


CollecCowhich are the Basic features of implementations of interfaces in Collections
Framework in java?
Carefully read the question and answer accordingly.
CollecMe
Map is the super class of Dictionary class?
Carefully read the question and answer accordingly.
CollecMe
what is the way to iterate over the elements of a Map

Carefully read the question and answer accordingly.


Consider the following Statements:
Statement A: The Iterator interface declares only two methods:
CollecMehasMoreElements 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?
Carefully read the question and answer accordingly.
Consider the following list of code:
A) Iterator iterator = hashMap.keySet().iterator();
B) Iterator iterator = hashMap.iterator();
C) Iterator iterator = hashMap.keyMap().iterator();
CollecMeD) 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?

Carefully read the question and answer accordingly.


CollecMeList<Integer> newList=new ArrayList<integer>(); will Above statement
create a new object of Array list successfully ?
Carefully read the question and answer accordingly.
CollecMe
Is "Array" a subclass of "Collection" ?

Carefully read the question and answer accordingly.


CollecCo
Is this true or false. Map interface is derived from the Collection interface.

Carefully read the question and answer accordingly.


What will be the output for following code?
public class Compare
{
public static void main(String[]args)
CollecMe{
String s=new String("abc");
String s1=new String("abc");
System.out.println(s.compareTo(s1));
}
}

Carefully read the question and answer accordingly.


CollecMeMethod keySet() in Map returns a set view of the keys contained in that map.
State True or False.

Carefully read the question and answer accordingly.


Which of the following are synchronized?
1.Hashtable
CollecCo
2.Hashmap
3.Vector
4.ArrayList

Carefully read the question and answer accordingly.


Consider the following statements about the Map type Objects:
Statement A: Changes made in the set view returned by keySet() will be
CollecMe
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?

Carefully read the question and answer accordingly.


CollecCo
When comparable interface is used which method should be overridden?
Carefully read the question and answer accordingly.
CollecMeIterator is having previous() method.
State True or False.
Carefully read the question and answer accordingly.
CollecMe
The ArrayList<String> is immutable.
Carefully read the question and answer accordingly.
String MeState whether TRUE or FALSE.
StringTokenizer implements the Enumeration interface

Carefully read the question and answer accordingly.


What will be the output for following code?
public class StringCompare{
public static void main(String[]args){
if("string"=="string")
String Me
System.out.println("both strings are equal");
else
System.out.println("both strings are not equal");
}
}

Carefully read the question and answer accordingly.


String MeState whether TRUE or FALSE.
The APIS of StringBuffer are synchronized unlike that of StringBuilder

Carefully read the question and answer accordingly.


String MeState whether TRUE or FALSE.
StringBuilder is not thread-safe unlike StringBuffer

Carefully read the question and answer accordingly.


What will be the output for following code?
public class StringBuffer1
{
public static void main(String[]args)
{
String Me
StringBuffer s1=new StringBuffer("welcome");
StringBuffer s2=new StringBuffer("welcome");
System.out.println(s1.equals(s2));
System.out.println(s1.equals(s1));
}
}

Carefully read the question and answer accordingly.


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

Carefully read the question and answer accordingly.


Choose the correct option.
String MeStatement I: StringBuilder offers faster performance than StringBuffer
Statement II: All the methods available on StringBuffer are also available on
StringBuilder

Carefully read the question and answer accordingly.


String MeendsWith() member methods of String class creates new String object. State
True or False
Carefully read the question and answer accordingly.
Choose the correct option.
String MeStatement 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.
Carefully read the question and answer accordingly.
String MeState whether TRUE or FALSE.
String s = new String(); is valid statement in java

Carefully read the question and answer accordingly.


Consider the following code snippet:
String thought = "Green";
String Me 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 accordingly.


String Me
String class contains API used for

Carefully read the question and answer accordingly.


What is the output of below code:
package p1;
public class Hackathon {
public static void main(String[] args) {
String Me
String x = "Java";
x.concat(" Rules!");
System.out.println("x = " + x);
}
}
Carefully read the question and answer accordingly.
What will be the output for following code?
public class CompareStrings{
public static void main(String[]args){
if(" string ".trim()=="string")
String Me
System.out.println("both strings are equal");
else
System.out.println("both strings are not equal");
}
}

Carefully read the question and answer accordingly.


What will be the output for following code?
import java.util.*;
public class StringTokens
{
public static void main(String[]args)
String Me
{
String s="India is a\n developing country";
StringTokenizer o=new StringTokenizer(s);
System.out.println(o.countTokens());
}
}

Carefully read the question and answer accordingly.


What is the output of below code:
package p1;
public class Hackathon {
public static void main(String[] args) {
String Me
String x = "Java";
x.toUpperCase();
System.out.println("x = " + x);
}
}
Carefully read the question and answer 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;
ExceptCo return;
}catch(Exception e)
{
System.out.println("welcome");
}
System.out.println("error");
}
}
1.welcome
2.error
3.compilation error

Carefully read the question and answer 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){
ExceptMe
try{
System.out.println("welcome");
return;
}catch(Exception e1){
}
System.out.println("error");
}
}
}
Carefully read the question and answer accordingly.
What will be the output for following code?
class super5{
void Get()throws Exception{
System.out.println("IOException");
}
}
public class Exception2 extends super5{
ExceptMe
public static void main(String[]args){
super5 o=new super5();
try{
o.Get();
}catch(IOException e){
}
}
}

Carefully read the question and answer accordingly.


ExceptMePropagating exceptions across modules is not possible without throw and
throws keyword. State True or False.

Carefully read the question and answer 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) {
ExceptCoSystem.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.

Carefully read the question and answer accordingly.


ExceptMe
try and throws keywords are used to manually throw an exception?
Carefully read the question and answer accordingly.
ExceptMeRuntimeException 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 accordingly.
ExceptMe
Error is the sub class of Throwable

Carefully read the question and answer accordingly.


At Point X in below code, which code is necessary to make the code
compile?
public class Test
{
class TestException extends Exception {}
ExceptCo
public void runTest() throws TestException {}
public void test() /* Point X */
{
runTest();
}
}

Carefully read the question and answer accordingly.


Consider the following code:
1 public class FinallyCatch {
2 public static void main(String args[]) {
3 try {
ExceptCo
4 throw new java.io.IOException();
5 }
6 }
7 }
Which of the following is true regarding the above code?

Carefully read the question and answer accordingly.


ExceptCo
Which is/are true among given statements

Carefully read the question and answer accordingly.


ExceptMe
is it valid to place some code in between try and catch blocks.
Carefully read the question and answer accordingly.
ExceptMe
Which is the super class for Exception and Error?
Carefully read the question and answer accordingly.
If you put a finally block after a try and its associated catch blocks, then once
ExceptCoexecution enters the try block, the code in that finally block will definitely be
executed except in some circumstances.select the correct circumstance from
given options:
Carefully read the question and answer accordingly.
Which of the following are checked exceptions?
1.ClassNotFoundException
ExceptCo
2.InterruptedException
3.NullPointerException
4.ArrayIndexOutOfBoundsException
Carefully read the question and answer accordingly.
ExceptMe
Which of the following statement is true regarding try-catch-finally?

Carefully read the question and answer accordingly.


ExceptMeThe finally block always executes when the try block exits.
State True or False.

Carefully read the question and answer accordingly.


What will be the output of following code?
try
{
System.out.println("Executing try");
ExceptCo}
System.out.println("After try");
catch (Exception ex)
{
System.out.println("Executing catch");
}

Carefully read the question and answer accordingly.


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++;
ExceptMe
} catch(Exception e) {
System.out.println(2);
} catch(ArithmeticException e) {
System.out.println(0);
}
finally {
System.out.println(3);
}
}
}
Carefully read the question and answer accordingly.
What will be the output of the below code?
public class Test {
public static void main(String[] args) {
int a = 5, b = 0, c = 0;
String s = new String();
try {
System.out.print("hello ");
System.out.print(s.charAt(0));
c = a / b;
ExceptCo } 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");
}
}
}

Carefully read the question and answer accordingly.


ExceptMe
Which of these keywords is used to explicitly throw an exception?

Carefully read the question and answer accordingly.


What will be the output for following code?
public class Exception1
{
public static void main(String[]args)
{
System.out.println("A");
try
{
ExceptCo
System.exit(0);
}catch(Exception e)
{
System.out.println("B");
}
System.out.println("C");
}
}
}

Carefully read the question and answer accordingly.


ExceptCo
which of these are the subclass of Exception class
Carefully read the question and answer accordingly.
ExceptMe
Which of these keywords are a part of exception handling?
Carefully read the question and answer accordingly.
Consider the following code:
class MyException extends Throwable { }
public class TestThrowable {
public static void main(String args[]) {
try {
test();
} catch(Throwable ie) {
ExceptCo System.out.println("Exception");
}
}

static void test() throws Throwable {


throw new MyException();
}
}
Which of the following option gives the output for the above code?

Carefully read the question and answer accordingly.


What will be the output of the program?
public class Test {
public static void aMethod() throws Exception {
try {
throw new Exception();
} finally {
System.out.print("finally");
}
ExceptCo}
public static void main(String args[]) {
try {
aMethod();
} catch (Exception e) {
System.out.print("exception ");
}
System.out.print("finished"); /* Line 24 */
}
}

Carefully read the question and answer accordingly.


ExceptCo
what are true for RuntimeException

Carefully read the question and answer accordingly.


Within try block if System.exit(0) is called then also finally block is going to be
ExceptCo
executed.
State True or False.
Carefully read the question and answer accordingly.
ExceptMeselect true or false . Statement : Throwable is the super class of all
exceptional type classes.
Carefully read the question and answer accordingly.
Select two runtime exceptions.
1.SQLException
ExceptMe2.NullPointerException
3.FileNotFoundException
4.ArrayIndexOutOfBoundsException
5.IOException

Carefully read the question and answer accordingly.


ExceptCo
which are true for try block

Carefully read the question and answer accordingly.


ExceptMeTry can be followed with either catch or finally.
State True or False.

Carefully read the question and answer accordingly.


ExceptMe
which are correct for checked exceptions

Carefully read the question and answer accordingly.


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
ExceptCo
{
}
catch(IOException t)
{
System.out.println("B");
}

System.out.println("C");
}
}

Carefully read the question and answer accordingly.


Which of the following statement is true regarding implementing user defined
ExceptMeexception 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

Carefully read the question and answer accordingly.


ExceptCo
which are the Unchecked exceptions

Carefully read the question and answer accordingly.


ExceptMe
Which of the following exception is not mandatory to be handled in code?
Carefully read the question and answer accordingly.
Statement 1:static variables can be serialized
I/O OpSi
Statement2:transient variables cannot be serialized
which of the following is true?

Carefully read the question and answer accordingly.


State TRUE or FALSE.
I/O OpSi
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 accordingly.


I/O OpSi
Which of these interface is not a member of java.io package?

Carefully read the question and answer accordingly.


I/O OpSi BufferedWriter constructor CAN ACCEPT Filewriter Object as a parameter.
State True or False.

Carefully read the question and answer accordingly.


I/O OpSi Which of these class are related to input and output stream in terms of
functioning?

Carefully read the question and answer accordingly.


What is the output of this program?
1. import java.io.*;
2. class files {
I/O OpSi 3. public static void main(String args[]) {
4. File obj = new File("/java/system");
5. System.out.print(obj.getName());
6. }
7. }
Carefully read the question and answer accordingly.
I/O OpSi
isFile() returns true if called on a file or when called on a directory
Carefully read the question and answer accordingly.
I/O OpSi Serialization is representing object in a sequence of bytes. State True or
False.
Carefully read the question and answer accordingly.
An ObjectInputStream deserializes objects previously written using an
I/O O Si
ObjectOutputStream.
State True or False.
Carefully read the question and answer accordingly.
I/O OpSi InputStream is the class used for stream of characters.
State True or False.

Carefully read the question and answer accordingly.


I/O OpSi
select the correct statements about BufferedOutputStream class

Carefully read the question and answer accordingly.


I/O OpSi
Which of the following is a marker interface used for object serialization?
Carefully read the question and answer accordingly.
I/O OpSi
DataInputStream is not necessarily safe for multithreaded access.
Carefully read the question and answer accordingly.
I/O OpSi
Which of these class are the member class of java.io package?
Carefully read the question and answer accordingly.
I/O OpSi
InputStreamReader is sub class of FilterReader.
Carefully read the question and answer accordingly.
I/O OpSi The InputStream.close() method closes this stream and releases all system
resources
Carefully read the question and answer accordingly.
I/O OpSi
Serialization is JVM independent.State True or False.
Carefully read the question and answer accordingly.
Which of the following are abstract classes?
1.Reader
I/O OpSi
2.InputStreamReader
3.InputStream
4.OutputStream

Carefully read the question and answer accordingly.


What is the value of variable "I" after execution of following code?
public class Evaluate
{
public static void main(String[]args)
{
ControMe int i=10;
if(((i++)>12)&&(++i<15))
System.out.println(i);
else
System.out.println(i);
}
}

Carefully read the question and answer accordingly.


ControMe
_____________ is a multi way branch statement

Carefully read the question and answer accordingly.


What will be the output for following code?
public class Wrapper11
{
public static void main(String[]args)
ControMe
{
Long l=100;
System.out.println(l);
}
}
Carefully read the question and answer accordingly.
What will be the output for following code?
public class WrapperClass12
{
public static void main(String[]args)
ControMe{
Boolean b=true;
boolean a=Boolean.parseBoolean("tRUE");
System.out.println(b==a);
}
}

Carefully read the question and answer accordingly.


ControMeWe can use Wrapper objects of type int, short, char in switch case.
State True or False.

Carefully read the question and answer accordingly.


ControMe
What is the number of bytes used by Java primitive long
Carefully read the question and answer accordingly.
ControMe
Data can be passed to the function ____

Carefully read the question and answer accordingly.


ControMe
Which of the following is a loop construct that will always be executed once?

Carefully read the question and answer accordingly.


What will be the output for following code?
public class WrapperClass1 {
public static void main(String[]args){
ControMeString s="10Bangalore";
int i=Integer.parseInt(s);
System.out.println(i);
}
}

Carefully read the question and answer accordingly.


What will be the output for following code?
public class Wrapper2 {
public static void main(String[]args){
ControMeByte b=1;
Byte a=2;
System.out.println(a+b);
}
}

Carefully read the question and answer accordingly.


What will be the output for following code?
public class WrapperClass1 {
public static void main(String[]args){
ControMeInteger i=new Integer(10);
Integer j=new Integer(10);
System.out.println(i==j);
}
}
Carefully read the question and answer accordingly.
ControMe
The result of 10.987+”30.765” is _________________.

Carefully read the question and answer accordingly.


What will be the output for following code?
public class While {
static int i;
public static void main(String[]args){
System.out.println(i);
ControMe
while(i<=5){
i++;
}
System.out.println(i);
}
}

Carefully read the question and answer 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;
ControMewhile(a<='Z'){
a++;
}
System.out.println(i);
System.out.println(a);
}
}

Carefully read the question and answer accordingly.


ControMeThe ______ statement is used inside the switch to terminate a Statement
sequence

Carefully read the question and answer accordingly.


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);
ControMe
}
static void method(Integer I) {
System.out.print(" Wrapper");
}
static void method(int i) {
System.out.print(" Primitive");
}
}
Carefully read the question and answer accordingly.
What happens when the following code is compiled and run. Select the one
correct
ControMeanswer.
for(int i = 1; i < 3; i++)
for(int j = 3; j >= 1; j--)
assert i!=j : i;

Carefully read the question and answer accordingly.


ControMe
Each case in switch statement should end with ________ statement

Carefully read the question and answer accordingly.


JDBC Co
- Which method executes a simple query and returns a single Result Set
object?
Carefully read the question and answer accordingly.
JDBC Co
-
Which object allows you to execute parametrized queries?

Carefully read the question and answer accordingly.


Which statements about JDBC are true?
1.JDBC has 5 types of Drivers
JDBC Co
- 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

Carefully read the question and answer accordingly.


JDBC Co
-
Which type of Statement can execute parameterized queries?

Carefully read the question and answer accordingly.


You are using JDBC-ODBC bridge driver to establish a connection with a
JDBC Co
-
database. You have created a DSN Mydsn. Which statement will you use to
connect to the database?

Carefully read the question and answer accordingly.


JDBC Me
-
The method Class.forName() is a part of JDBC API. State True or False.

Carefully read the question and answer accordingly.


JDBC Co
- Connection object can be initialized using which method of the Driver
Manager class?
Carefully read the question and answer accordingly.
JDBC Me
- Which type of driver converts JDBC calls into the network protocol used by
the database management system directly?
Carefully read the question and answer accordingly.
Which of the following is true with respect to code given below?
import java.sql.*;
public class OracleDemo
{
public static void main(String [] args) throws
SQLException,ClassNotFoundException
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
JDBC Co
-
con=DriverManager.getConnection("jdbc:oracle:thin:@PC188681:1521:traini
ng","scott","tiger");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT * FROM Person");
while(rs.next())
{
System.out.println(rs.getString("column1"));
}
}
}

Carefully read the question and answer accordingly.


JDBC Me
- The JDBC-ODBC Bridge driver translates the JDBC API to the ODBC API
and used with which of the following:
Carefully read the question and answer accordingly.
JDBC Me
- Type 1 & Type 3 driver types are not vendor specific implementation of Java
driver. State True or False

Carefully read the question and answer accordingly.


JDBC Co
-
Which method executes an SQL statement that may return multiple results?

Carefully read the question and answer accordingly.


JDBC Co
- Which package contains classes that help in connecting to a database,
sending SQL statements to the database, and processing the query results

Carefully read the question and answer accordingly.


JDBC Co
- What is the state of the parameters of the PreparedStatement object when
the user clicks on the Query button?
Carefully read the question and answer accordingly.
JDBC Me
- Which of the following listed option gives the valid type of object to store a
date and time combination using JDBC API?
Carefully read the question and answer accordingly.
If your JDBC Connection is in auto-commit mode, which it is by default, then
JDBC Co
-
every SQL statement is committed to the database upon its completion.
State True or False.

Carefully read the question and answer accordingly.


JDBC Co
-
How can you execute a stored procedure in the database?

Carefully read the question and answer accordingly.


JDBC Co
-
Which object provides you with methods to access data from the table?
Carefully read the question and answer accordingly.
JDBC Co
-
What is correct about DDL statements?

Carefully read the question and answer accordingly.


JDBC Me
- executeUpdate() & execute() are valid methods that can be used for
executing DDL statements. State True or False
Carefully read the question and answer accordingly.
JDBC Co
- A Java program cannot directly communicate with an ODBC driver because
of which of the following:

Carefully read the question and answer accordingly.


Consider the following statements:
Statement A: The PreparedStatement object enables you to execute
JDBC Co
- 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?

Carefully read the question and answer accordingly.


JDBC Co
-
Which packages contain the JDBC classes?

Carefully read the question and answer accordingly.


JDBC Co
-
Which method sets the query parameters of the PreparedStatement Object?

Carefully read the question and answer accordingly.


Consider you are developing a JDBC application, where you have to retrieve
ScenarMethe 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?

Carefully read the question and answer accordingly.


ScenarCoWhich collection class allows you to grow or shrink its size and provides
indexed access to its elements, but whose methods are not synchronized?

Carefully read the question and answer accordingly.


Consider you are developing a JDBC application, where you have to retrieve
ScenarCoEmployee table schema information like table columns name, columns field
length and data type etc. Which API you will use to retrieve table schema
information?
Carefully read the question and answer accordingly.
In Thread implementation methods like wait(), notify(), notifyAll() should be
ScenarMe
used in synchronized context .
State true or false
Carefully read the question and answer accordingly.
Consider you are developing an application where you have to store and
ScenarMe
retrieve data in character format in file. Which API you will use to store and
retrieve the data in character format?
Carefully read the question and answer accordingly.
ScenarCoWhich of the following provides an efficient means of storing key/value pairs
in sorted order, and allows rapid retrieval?

Carefully read the question and answer accordingly.


Consider you are developing a JDBC application, where you have to retrieve
ScenarMequarterly 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?

Carefully read the question and answer accordingly.


Interfaces are mainly used to expose behavior or functionality not the
ScenarMe
implementation code.
State true or false
Carefully read the question and answer accordingly.
ScenarMeSelect the advantages of using Collection API’s in java application
development.
Carefully read the question and answer accordingly.
Which statements are true about comparing two instances of the same class,
ScenarMe
given that the
equals() and hashCode() methods have been properly overridden?

Carefully read the question and answer accordingly.


Consider you are developing java application in a team consists of 20
developers and you have been asked to develop class by Name
ProgrammerAnalyst and to ensure that other developers in team use
ScenarMe
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?

Carefully read the question and answer accordingly.


Consider a development scenario where you want to write the object data
ScenarMe
into persistence storage devices (like file, disk etc.).Using which of the below
concept you can achieve the given requirement?

Carefully read the question and answer accordingly.


ScenarMe
Which of the following statement is incorrect?

Carefully read the question and answer accordingly.


Consider you are developing an ATM 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
ScenarCo
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?

Carefully read the question and answer accordingly.


ScenarMeWhich of these is executed first before execution of any other thing takes
place in a program?
Carefully read the question and answer accordingly.
Consider you are trying to persist or store object of Customer class using
ObjectOutputStream class in java. When you are trying to persist customer
ScenarCo
object data java code is throwing runtime exception without persisting object
information. Please suggest what is the key important factor you have
consider in code in order to persist customer object data.

Carefully read the question and answer accordingly.


ScenarCoWhich class does not override the equals() and hashCode() methods,
inheriting them directly from class Object?
Carefully read the question and answer accordingly.
ScenarMeWhat will happen if two thread of same priority are called to be processed
simultaneously?
Carefully read the question and answer accordingly.
In Thread implementation making method synchronized is always better in
order to increase application performance rather than using synchronize
ScenarMe
block to synchronize certain block of statements written in java inside the
method.
State True or False.

Carefully read the question and answer accordingly.


ScenarCoWhich of the following is incorrect statement regarding the use of generics
and parameterized types in Java?

Carefully read the question and answer accordingly.


Consider the development scenario where you have created Employee class
with implementation code and as per the project requirement you have to
ScenarCoensure 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?

Carefully read the question and answer accordingly.


You need to store elements in a collection that guarantees that no duplicates
ScenarCo
are stored and all elements can be accessed in natural order. Which interface
provides that capability?

Carefully read the question and answer accordingly.


Consider you are developing shopping cart application you have to store
details of items purchased by the each customer in intermediate memory
ScenarMebefore 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?
Choice1 Choice2

Compiles and display 2 Compiles and runs without any output

Compiles and prints show() Compiles and prints Display() show()

Compilation error Comiples and prints From A

0,0 compiles successfully but runtime error

code compiles fine and will display 23 code compiles but will not display output
compile error Man Dog Cat Ant

Unresolved compilation problem: The local


variable i1 may not have been initialized

Compilation error Runtime Exception


100 100 1 2 10 20 1 2 100 100 10 20

prints Hi Hello Compiler Error

int Long Short Long


A Sequence of 5 zero's will be printed like 0 A Sequence of 5 one's will be printed like 1 1
0000 111

Compile time error referring to a cast


A random number between 1 and 10
problem

boolean b = TRUE; byte b = 256;


Constructor of A executes first, followed by Constructor of C executes first followed by
the constructor of B and C the constructor of A and B

200 100 followed by 200

Only B and C is TRUE Only A is TRUE


default zero one two default zero

Compiles but no output Compiles and diplay 0

Compiler Error: anar is referenced before it is


2
initialized

i = this.planets; i = this.suns;
Error: amethod parameter does not match
10 and 40
variable

Dog Ant Dog Man Cat Ant


It is not possible to declare a constructor as
Hellow
private

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


0 Compilation Error

Meal() Lunch() PortableLunch() Cheese() Meal() Cheese() Lunch() PortableLunch()


Sandwich() Sandwich()

compiles and display 0 compilation error


Cat Ant Dog Dog Cat Ant

The compiler will automatically change the The compiler will find the error and will not
private variable to a public variable make a .class file

A compilation error will occur at (Line no 2),


The program will compile without errors. since the class does not have a constructor
that takes one argument of type int.

String: String first, int: 11 int: 99, String: Int int: 27, String: Int first String: String first, int:
first 27

The returnValue can be any type, but will be


If the returnType is void then the returnValue
automatically converted to returnType when
can be any type
the method returns to the caller
3 1

methodRadius(x); sp.methodRadius(x);

Only B is TRUE Only A is TRUE

Compiles and displays Hi Compiles and throws run time exception


var1=10 , var2=10 0,0

Compile time error because i has not been


initialized

Compilation error Compiles but throws run time exception

Only A is TRUE All are TRUE

default public
It is not possible to declare a constructor
Hello
private

Only A and C is TRUE All are TRUE

Compiles and prints show() Compiles and prints Display() show()

Compiles and display Hi Compiles and throw run time exception

System.out.println(Math.ceil(-4.7)); System.out.println(Math.floor(-4.7));

hello Runtime Error


Compilation error Compiles and display 0

synchronized volatile

true false

Compilation error Compiles and display 0

The code will compile and run, printing out The compiler will complain that the Base
the words "My Func" class has non abstract methods
Compilation fails. Cannot add Toppings

we must use always extends and later we we must use always implements and later we
must use implements keyword. must use extends keyword.

sal details sal details per details

3 4
Legal at compile time, but might be illegal at
Illegal at compile time
runtime

Hello A Compilation error

public static int answer = 42; int answer;

150 mph Compilation error

A,B,E A,C,D
sum of byte 7 Compilation error

A Compilation error

Hello A Compilation error

class Vehicle { abstract void display(); } abstract Vehicle { abstract void display(); }

public final data type varaibale=intialization; static data type variable;

p0 = p1; p2 = p4;
Hello A Compilation error

Because of single inheritance, Mammal can Because of single inheritance, Mammal can
have no subclasses have no other parent than Animal

s 14 s 16

A Compilation error

An abstract class is one which contains some


An abstract class is one which contains
defined methods and some undefined
general purpose methods
methods

int total = total + r + s; final double circumference = 2 * Math.PI * r;


No—there must always be an exact match No—but a object of parent type can be
between the variable and the object assigned to a variable of child type.

run time error generic noise

Auto Bicycle Auto

Private methods cannot be overridden in A subclass can override any method in a


subclasses superclass
3 Compilation error

No—a variable must always be an object No—a variable must always be an object
reference type reference type or a primitive type

The code will fail to compile because the


The code will fail to compile because a call to
max() method in B passes the arguments in
a max() method is ambiguous.
the call super.max(y, x) in the wrong order.

If you define D e = (D) (new E()), then


Compilation fails, due to an error in line 3 e.methodB() invokes the version of
methodB() defined at line 9
If both a subclass and its superclass do not
A super() or this() call must always be
have any declared constructors, the implicit
provided explicitly as the first statement in
default constructor of the subclass will call
the body of a constructor.
super() when run

run time error generic noise

Canada Compilation error

A B

display Compilation error


(A) (A) & (C)

display Compilation error

super keyword this keyword

150 mph Compilation error

The Bar class is a subclass of Foo. The statement a.j = 5; is legal.

abstract and final public and abstract


Compilation of both classes A & B will fail Compilation of both classes will succeed

This is a final method illegal This is a final method Some error message

000 47 7 0
class AllMath extends DoMath { double interface AllMath implements MathPlus
getArea(int r); } { double getVol(int x, int y); }

From F1 function in Class_1 Class Compile time error

B b=c; A a2=(B)c;

The B class is a subclass of A. The statement b.f(); is legal


It can only be used in the parent's
Only one child class can use it
constructor
No—if a class implements several interfaces,
No—a class may not implement more than
each constant must be defined in only one
one interface
interface

100 Compilation error

sal details sal details per details

Fun Time Compilation error


Error at compile time 200

4, 4 4, 5
run time exception compile time error

hello compile error

1 2

The size of s is 4 The size of s is 5

java.util.HashSet java.util.LinkedHashSet
The program will compile and print the The program will compile and print the
following output: [B] following output: [B,A]

Vector class ArrayList class

1 12

Collection interface Collections class

2 -4 3 -5

Wed Jun 01 1983 244 JUN 01 1983


3 5

Integer Long

3, 2, 1, 1, 2, 3,

true false
Today is Holiday Today is Holiday

null -1

Compilation error prints 3,4,2,1,

A and B is TRUE A and D is TRUE

[1,4,6,8] [4,6,8,9] [1,8,6,4] [8,6,4,9]

tSet.clear(new Integer("1")); tSetdelete(new Integer("1"));


A and B is TRUE A and D is TRUE

Java.util.Map Java.util.List

The before() method will print 1 2 The before() method will print 1 2 3

Compilation fails. aAaA aAa AAaa AaA

java.util.SortedMap java.util.TreeMap
[1,3,2] [1,3,3,2]

A, B, C, B, C, A,

1 2
Compilation fails because of an error in line
The code runs with no output.
25

A and B is TRUE A and D is TRUE

[2,3,7,5] [2,3,4,5,6]

-1

{2=Two, 4=Four, 6=Six, 7=Seven} {4=Four, 6=Six, 7=Seven}

value = value + sum; sum = sum + 1; sum = sum + 1; value = value + sum;
int [] myList = {"1", "2", "3"}; int [] myList = (5, 8, 2);

Compilation error The variable first is set to null.

Hello World Compilation error

48 94

1 2

Hello World Compilation error

A sequence of five 10's are printed A sequence of Garbage Values are printed
The program will compile, and print |null| The program will compile, and print |null|true|
false|0|0.0|0.0|, when run 0|0.0|100.0|, when run

4 Compilation error

The returnValue can be any type, but will be


The returnValue must be exactly the same
automatically converted to returnType when
type as the returnType
the method returns to the caller.

compile time error at line 2 compile time error at line 4


args[2] = 2 args[2] = 3

Only A is TRUE Only B is True

10, 1 11, 1

3 Compilation error

value: 0 count: 0 value: 0 count: 1


012 23

compiles and runs with no output var = 1

Hello World Compilation error

Array a = new Array(5); int [] a = {23,22,21,20,19};


int [] myScores []; char [] myChars;

13 13.5
-1

Compilation error

t7 t9

x = -7, y = 1, z = 5 x = 3, y = 2, z = 6

10, 9, 8, 7, 6, 9, 8, 7, 6, 5,
10, 1 11, 1

a: 9 b:11 a: 10 b: 9

26 282

19 followed by 11 19 follwed by 20

int #ss; int 1ah;

Line 1, Line 5 Line 5

23 13
disp X = 6 main X=6 disp X = 5 main X=5

06172838 06172839

(A), (B) & (C) (A), (B), (C) & (D)

Compilation error

83886080 and -2 2 and 83886080


A B

It can be omitted, but if not omitted there are


It must always be private or public
several choices, including private and public

It is not possible super.doIt()

Aggregation Simple Association


rod = mos pkt = rat

Two objects and three reference variables. Three objects and two reference variables

92 91

false true

10 27

result =
result.concat( stringA, stringB, stringC );
stringA.concat( stringB.concat( stringC ) );

Only A is TRUE Only B is TRUE


hi hi hi world

K A

Only A is TRUE Only B is TRUE

Compilation and output the string "Hello" Compilation and output the string "ello"

result =
result.concat( stringA, stringB, stringC );
stringA.concat( stringB.concat( stringC ) );

203 204
acctna iccratna

if(s==s2) if(s.equals(s2))

Compilation fails The first line of output is abc abc false

bat at
78abc abc78

acitcratna acitrcratna

hi hi hi world

abc def abc def ghi

abcdefabcdef     abcabcDEFDEF

4 2
Cognizant Technology Solutions Cognizant Technology

One ring to rule them all, One ring to find One ring to rule them all, One ring to find
them. them.

-6 6

The code will fail to compile because the


expression str3.concat(str1) will not result in The program will print str3str1str2,when run
a valid argument for the println() method

tica anta

788232 7914
1

A B

x.delete() x.finalize()

This is java Thi is java


1

Garbage collection cannot be forced Call System.gc()

An object is deleted as soon as there are no The finilize() method will eventually be called
more references that denote the object on every object

count < 9 count+1 <= 8

2 24
Compilation error 1515

Compilation fails. granite granite

Person[] p []; Person p[][] = new Person[2][];

hi hi hi world

23 32
00 0001

012 012122

Compilation error Compiles but no output


If a is true and b is false then the output is If a is true and b is true then the output is "A
"notB" && B"

Compilation error true

true false

R.T.Ponting C.H.Gayle
81 91

7 Compilation error

value = 6 value = 4
An exception is thrown at runtime. [608, 610, 612, 629] [608, 610, 629]

0001 000120

x=1 x=3

r, t, t, r, e, o,

TreeMap HashSet
b = nf.parse( input ); b = nf.format( input );

3 2

2 <= r <= 9 3 <= r <= 10

HashTable is a sub class of Dictionary ArrayList is a sub class of Vector

There are syntax errors on lines 1 and 6 There are syntax errors on lines 1, 6, and 8

Compilation error 2.147483648E9


No, Compilation error Yes, 10, 100

5,6 6,5

s += i * i; s++;

String is a wrapper class Double has a compareTo() method

tSet.headSet tset.headset
one two three four four three two one

23 Compilation error

Changes made in the Set view returned by


The return type of the values() method is set
keySet() will be reflected in the original map

harrier shepherd

0 null Compiles but error at run time


bat man Compilation error

A continue statement doesn’t transfer control


An overflow error can only occur in a loop
to the test statement of the for loop

14 28

very short average

2211 3 2 1 null
good good morning morning ….

default default brownie

You win You lose

The code will fail to compile because the


The code will fail to compile because the
compiler will not be able to determine which if
syntax of the if statement is incorrect
statement the else clause belongs to
20 21

To write characters to an outputstream, you


To write an object to a file, you use the class
have to make use of the class
ObjectFileWriter
CharacterOutputStream.

compilation error apple

2 and 4 1 ,3 and 5
M.S.Dhoni all of these

none of the listed options runtime error

Compiles but error at run time 46

collie harrier
Prints: false, false, false Prints: false, false, true

123 3

9 5
Compilation fails. pi is bigger than 3.

Compilation fails j = -1

run time error good

5,6 5,5
int, int Integer, new

dollorpack.$pack.$$pack $$.$$.$$

Java Compiler (Javac) Java Runtime Environment (JRE)

Holds the location of Core Java Class Library


Holds the location of Java Extension Library
(Bootstrap classes)

String[] args String args[]

Packages can contain both Classes and


Packages can contain only Java Source files
Interfaces (Compiled Classes)

Object class is an abstract class Object class cannot be instantiated directly

Helps the compiler to find the source file that


To maintain the uniform standard corresponds to a class, when it does not find
a class file while compiling

compilation error will display Hi once

new Thread(MyRunnable).run(); new MyRunnable().start();


Will create two child threads and display Hi
will not create any child thread
twice

will print Hi twice and throws Exception at run


will print Hi Thrice
time

public class MyRunnable extends public class MyRunnable implements


Runnable{public void run(){}} Runnable{void run(){}}
Prints "Inside Thread Inside Thread" Prints "Inside Thread Inside Runnable"

run() notify()
Thread class none of the listed options

It will start a new thread compilation error

will print Hi twice and throws exception at


will print Hi Once
runtime
Compilation fails An exception occurs at runtime.

The output could be 6-1 6-2 5-1 7-1 The output could be 5-1 6-1 6-2 5-2

The code executes normally, but nothing is


Compilation fails.
printed.
Only C and D is TRUE Only A and B is TRUE

start(); register();

Implement java.lang.Thread and implement Implement java.lang.Thread and implement


the run() method. the start() method.

An exception is thrown at runtime. Compilation fails.

After thread A is notified, or after two


Two seconds after thread A is notified.
seconds.

Both A and B are TRUE Only B is TRUE

METHOD SOURCE
@interface @inherit
Override Retention
true false

method class

Information For the Compiler Information for the JVM


State Behaviour
Efficient utilization of memory at runtime Code reuse
Ford - Car Microprocessor - Computer
void add(int x,int y) char add(int x,int y) char add(float x) char add(float y)
Composition Inheritance
A try statement must have at least one Multiple catch statements can catch the same
corresponding catch block class of exception more than once.

End of method. java.lang.RuntimeException:


java.lang.RuntimeException: Problem
Problem

Code output: Start Hello world End of file Code output: Start Hello world Catch Here
exception. File not found.

throw Exception throws Exception


Compilation fails ParseException thrown at runtime

Any statement that can throw an Error must Any statement that can throw an Exception
be enclosed in a try block. must be enclosed in a try block.

One Two Catch Finally One Catch

True False

Compilation fails. finally exception

The notifyAll() method must be called from a To call sleep(), a thread must own the lock on
synchronized context the object

Arithmetic Exception IOException


true Not true

If run with no arguments,the program will If run with no arguments,the program will
produce no output produce "The end"

none of the listed options runtime error

Arithmetic Exception Runtime Exception Runtime Exception

If a class has synchronized code, multiple


A static method cannot be synchronized. threads can still access the nonsynchronized
code.
Since the method foo() does not catch the
exception generated by the method baz(),it A try block cannot be followed by both a
must declare the RuntimeException in a catch and a finally block
throws clause

Checked exceptions Unchecked exceptions

caught exit exit RuntimeException thrown at run time

Thread t = new Thread(); x.run(); Thread t = new Thread(X);

Implement java.lang.Runnable and Extend java.lang.Thread and override the


implement the run() method. run() method.
1, 4, 5 and 6 1, 2, 3 and 4

static methods are difficult to maintain, static methods can be called using an object
because you can not change their reference to an object of the class in which
implementation. this method is defined.

ClassCastException NumberFormatException

sleep() yield()

Try Block Finally Block Try Block

bark meow
caught exit exit

test end test runtime end

Exception occurred RuntimeException

Deadlock will not occur if wait()/notify() is The wait() method is overloaded to accept a
used duration
prints 12 12 12 12 DeadLock

ClassCastException NullPointerException

volatile synchronized
hello throwit caught Compilation fails

5 Compilation error

exit Compiles and no output


Only A is TRUE Only B is TRUE

The program will print Hello world, then will


print that a RuntimeException has occurred,
The program will not compile.
then will print Done with try block, and then
will print Finally executing.

true false

We cannot have a try block without a catch


Java is portable
block

Compilation fails
The program will only print 5 The program will only print 1 and 4 in order

Synchronizing the run() method would make


An exception is thrown at runtime.
the class thread-safe.

Statement 2 is TRUE but Statement 1 is


Both Statement 1 & Statement 2 are FALSE.
FALSE.
X run = new X(); Thread t = new Thread(run);
Thread t = new Thread(X);
t.start();

X, followed by an Exception. No output, and an Exception is thrown.

1, 2, 4 2, 4, 5
hello throwit caught finally after hello throwit caught

A compile time error indicating that no run A run time error indicating that no run method
method is defined for the Thread class is defined for the Thread class
567 5 followed by an exception

finished Exception

Exception A,B,Exception
reads data from file named jlist.lst in byte
Compilation error
form and display it on console.

reads data from file one byte at a time and


Compilation error
display it on the console.

The program will not compile because a The program will compile and print H|e|l|l|o|
certain unchecked exception is not caught. Input error.
I am a Person I am a Student

Skip the first seven characters and then


Compilation error
starts reading file and display it on console

reads data from file named jlist.lst in byte


Compilation error
form and display it on console.

A,D B,C

the state of the object s1 will be store to file


Compilation error
std.txt
reads data from file one byte at a time and
Compilation error
display it on the console.

throws a DataFormatException throws a FileNotFoundException

Compilation fails An exception is thrown at runtime

writeBytes() writeFloat()

FileOutputStream fos = new FileOutputStream fos = new


FileOutputStream( "myData.stuff", true ) FileOutputStream( "myData.stuff")

A SecurityException is thrown The boolean value false is returned

The file system has a new empty directory The file system has a new empty directory
named dir named newDir
writes data to file in byte form. Compilation error

creates directories names prj and lib in d:


Compilation error
drive

Transfer content of file data to the temp.txt Compilation error

the state of the object s1 will be store to file


Compilation error
std.txt
ab abcd

creates directory d:/prj/lib Compilation error

s.writeInt(x); s.serialize(x);

Both A and B is FALSE Only A is TRUE

Both A and B is FALSE Only A is TRUE

DriverManager Class Driver Interface

Statement CallableStatement

executeUpdate() executeSQL()
true false

Only A and B is TRUE Only B and C is True

Using the static method registerDriver()


Using forName() which is a static method method which is available in DriverManager
Class.

There is no such method in ResultSet It returns true when last read column contain
interface SQL NULL else returns false

1) Driver 2) Connection 3) ResultSet 4)


1) Driver 2) Connection 3) ResultSet 4) ResultSetMetaData 5) Statement 6)
DriverManager 5) Class DriverManager 7) PreparedStatement 8)
Callablestatement 9) DataBaseMetaData

Line 16 is never executed An exception is thrown at runtime

true false
java.sql.ResultSet java.sql.Driver

will show first employee record Compilation error

Read Only, Forward Only Updatable, Forward only

will show all row of first column Compilation error

will show only name Compilation error

java.sql.Driver java.sql.Driver

Database.getMaxConnections Connection.getMaxConnections

executeAll() executeAllSQL()

true false
registerDriver() method Class.forName()

specifier Inheritance

protected ,interface final,interface

super class method display method 20 20 display method display method 10 10


10 11

TRUE FALSE

FALSE TRUE

Class Public

protected or default protected or public

super class show method sub class show


super class show method
method
I II & IV

FALSE TRUE

If one class is having protected method then


the method is available for subclass which is A class can be declared as protected.
present in another package

super class exe method sub class display super class exe method super class display
method method
Constructors can be overloaded Constructors can be overridden.

TRUE FALSE

TRUE FALSE

1&2 1&2&3
Child Parent Parent

1&2 1&3

TRUE FALSE

TRUE FALSE

final protected
Class cannot be defined inside another class Runtime Error.

TRUE FALSE
10 50 20 50

TRUE FALSE

TRUE FALSE

TRUE FALSE
TRUE FALSE

TRUE FALSE

TRUE FALSE
TRUE FALSE

public void aM2(){} public void aM1(){}


public void aM1(){} public void aM2(){} public void bM1(){} public void bM2(){}

they're not equal t1's an Object

Statement I & II are TRUE Statement I is TRUE & II is FALSE

TRUE FALSE

Statement I & II are TRUE Statement I is TRUE & II is FALSE


Human Can Walk Compilation Error

0, 0, 0 120, 60, 0
DigiCam do Charge You are Sending:
Compilation Error
MyFamily.jpg

The equals method does NOT properly Compilation fails because the private attribute
override the Object class's equals method. p.name cannot be accessed.

Statement I & II are TRUE Statement I is TRUE & II is FALSE


TRUE FALSE

Aggregation Composition

It will print ArithmeticException and prints 5 It will give ArithmeticException


Code will not compile due to weaker access
Code will Compile without any Error
privilege.

Statement I & II are TRUE Statement I is TRUE & II is FALSE


1&2 1&3

System.free(); System.setGarbageCollection();

Both Statements A and B Statement A alone

line 3 line 4
Both Statements A and B are true Statement A is true and Statement B is false

Option 2 Option 3

address dot

97 a

1 3

TRUE FALSE

try catch

TRUE FALSE
102 34

FALSE TRUE

12,12,-1 13,12,0

extends implements

class new

III->I->II->IV. I->III->II->IV
An exception is thrown at runtime. The code executes normally and prints "Run".

TRUE FALSE

Compile Error Important job running in MyThread


Compile Error Important job running in MyThread

It will compile and the run method will print It will compile and calling start will print out
out the increasing value of i. the increasing value of i.

Statement1 is TRUE but Statement2 is Statement2 is TRUE but Statement1 is


FALSE. FALSE.

TRUE FALSE
You cannot call run() method using Thread
An exception is thrown at runtime.
class object.

Exactly 10 seconds after the start method is Exactly 10 seconds after the “Start!” is
called, “Time’s Over!” will be printed. printed, “Time’s Over!” will be printed.

Runnable Running

1&2 1&3

void run() void start()

One Two
wait() notify()

Synchronized blocks Synchronized methods

Reduce response time of process. Support parallel operation of functions.

[10,abc] [10]

1&2 1&3

List Set

TRUE FALSE

Prints the output [Green World, 1, Green


Compilation error at line no 8
Peace] at line no 9
TRUE FALSE

TRUE FALSE

boolean void

Creates a Date object with '01-01-1970


Creates a Date object with 0 as default value
12:00:00 AM' as default value

The Iterator interface declares only three The ListIterator interface extends both the
methods: hasNext, next and remove. List and Iterator interfaces

int String

FALSE TRUE

TRUE FALSE

Line 1 has compilation error Line 2 has run time exceptions


TRUE FALSE

TRUE FALSE

Hash Map Array List

java.utill.Map java.util.ArrayList

Serializable SortTable

TRUE FALSE

The elements in the collection are accessed The elements in the collection are
using a unique key. guaranteed to be unique

All implementations support having null


All implementations are unsynchronized
elements.

TRUE FALSE

for loop list Iterator

Both the Statements A and B are true Statement A is true and Statement B is false
A B

TRUE FALSE

TRUE FALSE

TRUE FALSE

True False

TRUE FALSE

1&2 1&3

Both Statements A and B are true Statement A is true and Statement B is false

comparator compare
FALSE TRUE

TRUE FALSE

TRUE FALSE

both strings are equal both strings are not equal

TRUE FALSE

TRUE FALSE

true true false true

both strings are equal both strings are not equal


TRUE FALSE

Statement I & II are TRUE Statement I is TRUE & II is FALSE

FALSE TRUE

Statement I & II are TRUE Statement I is TRUE & II is FALSE

FALSE TRUE

TRUE FALSE

Comparing strings Searching strings

Error x = Java Rules


both strings are equal both strings are not equal

4 5

x = JAVA x=""
1&2 1&2&3

welcome error
IOException compilation error

TRUE FALSE

1&2 1&2&3

TRUE FALSE
TRUE FALSE

TRUE FALSE

throws RuntimeException catch ( Exception e )

Shows unhandled exception type Shows unhandled exception type


IOException at line number 4 IOException at line number 5

NoClassDefFoundError means that the class


A ClassNotFoundException is thrown when
was found by the ClassLoader however when
the reported class is not found by the
trying to load the class, it ran into an error
ClassLoader in the CLASSPATH.
reading the class definition.

TRUE FALSE

Throwable throws

An exception arising in the finally block itself The use of System.exit()

1&2 1&3
An exception which is not handled by a catch
A catch block can have another try block
block will be handled by subsequent catch
nested inside
blocks

TRUE FALSE

Executing try After try Executing catch Executing try Runtime Exception

2 3
hello 0 stopped hello 0 Math problem occur stopped

try finally

A,C A

IOException Throwable

try final
Compiler time error User defined exceptions
Prints Exception
should extend Exception

exception finished Compilation fails

Runtime exceptions need not be explicitly


Runtime exceptions include arithmetic
caught in try catch block as it can occur
exceptions, pointer exceptions
anywhere in a program.

FALSE TRUE

TRUE FALSE
1&2 1&5

Try block always needed a catch block if exception occurs, control switches to
followed following first Catch block

TRUE FALSE

A checked exception is a subclass of


error and checked exceptions are same.
throwable class

Compile time error A

Both Statements A and B are true Statement A is true and Statement B is false

Class Cast Exception Array Index Out Of Bounds Exception

IOException FileNotFoundException
statement 1:true statement2:true statement 1:false statement2:true

TRUE FALSE

DataInput ObjectInput

TRUE FALSE

File Writer

java/system /java/system

TRUE FALSE

TRUE FALSE

TRUE FALSE

FALSE TRUE

setting up BufferedOutputStreaman , an
application can write bytes to the underlying
BufferedOutputStream class is a member of
output stream without necessarily causing a
Java.io package
call to the underlying system for each byte
written.

Runnable Serializable
TRUE FALSE

ObjectInput StringReader

TRUE FALSE

TRUE FALSE

TRUE FALSE

1&2 1&2&3

10 11

switch continue

100 Compilation error


True False

TRUE FALSE

The number of bytes is compiler dependent 2

by value by reference

switch for

10Bangalore 10

compiles and print 3 compilation error

True False
10.98730.765 10.9873.765

compilation error 0,6

A,Z a,z

break Jump

Primitive Wrapper Wrapper


The class compiles and runs, but does not The number 1 gets printed with
print anything. AssertionError

default break

executeUpdate() executeQuery()

ResultSet Parametrized

1&2 3&4

PreparedStatement ParameterizedStatement

Connection Connection
cn=DriverManager.getConnection("jdbc:odbc cn=DriverManager.getConnection("jdbc:odbc:
"); Mydsn", "username", "password");

TRUE FALSE

putConnection() setConnection()

Type 1 driver Type 2 driver


The code will not compile as no try catch The code will display all values in column
block specified named column1

JDBC drivers ODBC drivers

TRUE FALSE

executeUpdate() executeQuery()

connection.sql db.sql

initialized started

java.util.Date java.sql.Date

TRUE FALSE

Call method execute() on a Call method executeProcedure() on a


CallableStatement object Statement object

ResultSet Parametrized
DDL statements are treated as normal SQL
statements, and are executed by calling the To execute DDL statements, you have to
execute() method on a Statement (or a sub install additional support files
interface thereof) object

TRUE FALSE

ODBC written in C language ODBC written in C# language

Statement A is True and Statement B is


Both Statement A and Statement B are True.
False.

java.jdbc and javax.jdbc java.jdbc and java.jdbc.sql

putString() insertString()

Statement PreparedStatement

java.util.HashSet java.util.LinkedHashSet

ResultSet ResultSetMetaData

TRUE FALSE

Reader and Writer Stream APIs InputStream and OutputStream Stream APIs
TreeMap HashMap

Statement PreparedStatement

TRUE FALSE

Reduces programming effort Allows interoperability among unrelated APIs

If the equals() method returns true, the


If the equals() method returns false, the
hashCode() comparison == might return
hashCode() comparison == might return true
false

Declare the ProgrammerAnalyst class has Declare the ProgrammerAnalyst class has
abstract private

finalization Serialization

By multithreading CPU’s idle time is


By multitasking CPU’s idle time is minimized,
minimized, and we can take maximum use of
and we can take maximum use of it.
it.

Using Thread Synchronization Using object serialization

main method finalize method


Check whether you have implemented Check whether you have implemented
Customer class with Serializable interface Customer class with Externalizable interface

java.lang.String java.lang.Double

Any one will be executed first lexographically Both of them will be executed simultaneously

FALSE TRUE

Generics provide type safety by shifting more Generics and parameterized types eliminate
type checking responsibilities to the the need for down casts when using Java
compiler. Collections.

Mark Employee class with abstract keyword Mark Employee class with final keyword

java.util.Map java.util.Set

Implement using Arrays Implement using Collection API’s.


Choice3 Choice4

Compiles and display 0 Compilation error

Compiles but throws runtime exception Compilation error

Compiles but throws runtime exception Compiles and display 3

compile error none of these

j can not be initialized compliation error


Dog Man Cat Ant Cat Ant Dog Man

Compilation and output of null None of the given options

2500 50
10 20 1 2 100 100 1 2 10 20 100 100

Runs but no output Runtime Error

Compilation fails. An exception is thrown at runtime.


Compilation Error occurs and to avoid them
IndexOutOfBoundes Error
we need to declare Mine class as abstract

A compile time error as random being an


A random number between 0 and 1
undefined method

String s = “null”; int i = new Integer(“56”);


Constructor of C executes first followed by the Constructor of A executes first followed by
constructor of B and A the constructor of C and B

Compile time error 100

All are FALSE Only A and C is TRUE


Compilation Error default

Compilation error Compiles and display 1

Compiler Error: size of array must be


1
defined

this = new ThisUsage(); this.i = 4;


10, and 20 20 and 40

Man Dog Ant Dog Man Ant


Compilation Error Runs without any output

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


It is not possible to access a static variable
Garbage Value
in side of non static method

Meal() Lunch() PortableLunch() Sandwich() Cheese() Sandwich() Meal() Lunch()


Cheese() PortableLunch()

Compiles and display 4 Compiles and display 3


Ant Cat Dog none

The program will compile successfully, but


The program will compile and run successfully
the .class file will not run correctly

A compilation error will occur at (Line no 1), A compilation error will occur at (2), since
since constructors cannot specify a return the class does not have a default
value constructor

Compilation Error Runtime Exception

The returnValue must be the same type as the


returnType, or be of a type that can be The returnValue must be exactly the same
converted to returnType without loss of type as the returnType.
information
2

Nothing to add Sphere.methodRadius();

Both are TRUE Both are FALSE

Compilation fails Compiles but doesn't display anything


compile error runtime error

It is not possible to declare a static variable


in side of non static method or instance
Compilation and output of null
method. Because Static variables are class
level dependencies.

Compiles and displays nothing None of the listed options

B and C is TRUE All are FALSE

transient synchronized
Can't create object because constructor is
Compilation Error
private

All are FALSE Only A is TRUE

Compiles but throws runtime exception Compilation error

Compiles but doesn't display anything Compilation fails

System.out.println(Math.round(-4.7)); System.out.println(Math.min(-4.7));

compiles but no output does not compile


Compiles and display 2 Compiles and runs without any output

transient default

Compiles and display 23 Compiles but no output

The compiler will complain that the method


The code will compile but complain at run time
myfunc in the base class has no body,
that the Base class has non abstract methods
nobody at all to print it
The code runs with no output. A NullPointerException is thrown

extends and implements can't be used


we can use in any order its not at all a problem
together

compilation error per details sal details

compilation error Compiles but error at runtime


Definitely legal at runtime, but the cast operator Definitely legal at runtime, and the cast
(Sub) is not strictly needed. operator (Sub) is needed.

Hello B Compiles but error at runtime

final static int answer = 42; public int answer = 42;

Compiles but error at run time 90 mph

B,D,E C,D,E
sum of int7 Compiles but error at runtime

Compiles but error at run time Runs but no output

Hello B Compiles but error at runtime

class abstract Vehicle { abstract void abstract class Vehicle { abstract void
display(); } display(); { System.out.println("Car"); }}

static final data type varaiblename; final data type variablename=intialization;

p1 = (ClassB)p3; p1 = p2;
Hello B Compiles but error at runtime

Because of single inheritance, Animal can Because of single inheritance, Mammal can
have only one subclass have no siblings.

s 10 Compilation fails.

Compiles but error at run time Runs but no output

An abstract class is one which contains only


Abstract class can be declared final
static methods

protected int CODE = 31337; int AREA = r * s;


Yes—an object can be assigned to a reference Yes—any object can be assigned to any
variable of the parent type. reference variable.

bark compile error

compile error runtime error

An overriding method can declare that it throws The parameter list of an overriding method
checked exceptions that are not thrown by the can be a subset of the parameter list of the
method it is overriding method that it is overriding
Compiles but error at run time 9

Yes—the variable can refer to any object


No—a variable must always be a primitive type
whose class implements the interface

The code will compile and print 29, when


The code will compile and print 23, when run.
run.

If you define D e = (D) (new E()), then


Compilation fails, due to an error in line 7 e.methodB() invokes the version of
methodB() defined at line 5
If neither super() nor this() is declared as the
If super() is the first statement in the body of
first statement in the body of a constructor,
a constructor, this() can be declared as the
this() will implicitly be inserted as the first
second statement
statement.

bark compile error

Compiles but error at run time null

C D

Compiles but error at run time Runs but no output


(D) (B) & (C)

Compiles but error at run time Runs but no output

cannot call because it is overridden in


by creating an instance of the base class
derived class

90 mph Compiles but error at runtime

The statement b.f(); is legal. The statement a.g(); is legal.

public ,static and final default and abstract


Compilation of class A will fail. Compilation of Compilation of class B will fail. Compilation
class B will succeed of class A will succeed

Compilation error illegal Some error message

Compilation error 47 47 47
abstract class AllMath implements DoMath,
class AllMath implements MathPlus
MathPlus { public double getArea(int rad)
{ double getArea(int rad); }
{ return rad * rad * 3.14; } }

Create an object for Interface only Runtime Error

C c2=(C)(B)c; A a1=(Test)c;

The statement a.j = 5; is legal. The statement a.g(); is legal


It must be used in the last statement of the It must be used in the first statement of the
constructor. constructor.
Yes— either of the two variables can be
Yes—since the definitions are the same it
accessed through :
will not matter
interfaceName.variableName

Compiles but error at run time Compiles but no output

compilation error per details sal details

Fun Run Compiles but error at runtime


100 followed by 200 100

5, 4 Compilation fails
hello hellohello

runtime error none

3 4

The size of subs is 3 The size of s is 7

java.util.List java.util.ArrayList
The program will compile and throw a runtime
The program will not compile
exception

Collection interface Collections class

14 123

Vector class ArrayList class

2 -6 3 -4

PST JUN 01 1983 GMT JUN 01 1983


compilation error Compiles but error at run time

int String

Compilation fails. The code runs with no output.

Compile time error Runtime Exception


Both none of the listed options

none of the listed options

prints 1,2,3,4 Compiles but exception at runtime

A and C is TRUE B and C is TRUE

[1,4,6,8,9] [4,6,8,9] [1,4,6,8,9] [4,6,8]

tSet.remove(new Integer("1")); tSet.drop(new Integer("1"));


A and C is TRUE B and D is TRUE

Java.util.Table Java.util.Collection

The before() method will throw an exception at


The before() method will not compile
runtime

AAaa AaA aAa aAaA AaA AAaa aAaA aAa

java.util.TreeSet java.util.Hashtable
[1,3,2,1,3,2] [3,1,2]

Compilation fails. An exception is thrown at runtime.

3 4
Compilation fails because of an error in line
An exception is thrown at runtime
21

A and C is TRUE B and D is TRUE

[2,3,7,5,4,6] [2,3,4,5,6,7]

null none of the listed options

{4=Four, 6=Six} {2=Two, 4=Four, 6=Six}

value = value + sum; value = value + ++sum;


int myList [] [] = {4,9,7,0}; int myList [] = {4, 3, 7};

The variable first is set to elements[0]. Compiles but error at runtime

Compiles but error at run time Compiles but run without output

Compiles but error at run time Compilation error

3 4

Compiles but error at run time Compiles but run without output

compile time Error Compiles but no output


The program will compile, and print | |false|0| The program will compile, and print |null|
0.0|0.0|, when run false|0|0.0|100.0|, when run

Compiles but error at run time

The returnValue must be the same type as


If the returnType is void then the returnValue the returnType, or be of a type that can be
can be any type converted to returnType without loss of
information.

prints 34,56 runtime exception


args[2] = null An exception is thrown at runtime

Both A and B is True Both A and B is FALSE

10, 0 11 , 0

Compiles but error at run time

value: 1 count: 1 value: 1 count: 2


000 An exception is thrown at runtime

does not compile run time error

Compiles but error at run time Compiles but run without output

int a [] = new int[5]; int [5] array;


int [6] myScores; Dog myDogs [];

13 Compilation Error
4 random value

A ParseException is thrown by the parse A NumberFormatException is thrown by the


method at runtime parse method at runtime

a9 Compilation error

x = 4, y = 1, z = 5 x = 4, y = 2, z = 6

Compilation fails An exception is thrown at runtime


10, 0 11 , 0

a: 9 b:9 a: 0 b:9

Compiles but error at run time Compilation error

Compile time error 10 followed by 1

int _; int $abc;

Line 1, Line 3, Line 5 Line 3

2 3
disp X = 5 main X=6 Compilation error

05152535 compilation fails

(C) & (D) (A) & (B)

Compiles but error at run time 4

2 and -83886080 83886080 and 2


C D

The access modifier must agree with the type It can be omitted, but if not omitted it must
of the return value be private or public

his.super.doIt() ((A) this).doIt();

Dependency Composition
pkt = null rod = rat

Four objects and two reference variables Two objects and two reference variables.

Compilation error 82

24 11

result =
result+stringA+stringB+stringC; concat(StringA).concat(StringB).concat(Stri
ngC)

Both A and B is TRUE Both A and B is FALSE


world Compilation error

R I

Both A and B is TRUE Both A and B is FALSE

Compilation and output the string elloH Compile time error

result =
result+stringA+stringB+stringC; concat(StringA).concat(StringB).concat(Stri
ngC)

205 Compilation error


ctna--------acitcratna
acctna
tna
ctna

if(s.equalsIgnoreCase(s2)) if(s.noCaseMatch(s2))

The first line of output is abcd abc false The second line of output is abcd abc false

atm Compilation error


Compilation error Compiles but exception at run time

4 Compilation fails.

accircratna accrcratna

world Compilation error

abc def + abc def +ghi

     abcdefabcDEF none of the listed options

6 Compilation error
Cognizant Solutions Technology Solutions

One ring to rule them all,\n One ring to find


Different Starts
them.

Compilation error

The program will print str3,when run The program will print str3str1,when run

Compilation error Complies but exception at run time

Compilation error Compiles but exception at run time


2 3

C D

Only the garbage collection system can


Runtime.getRuntime().gc()
destroy an object.

This i java Thi i java


2 3

Call System.gc() passing in a reference to the


Call Runtime.gc().
object to be garbage collected

An object will not be garbage collected as


The finalize() method will never be called more
long as it possible for a live thread to
than once on an object
access it through a reference.

count < 8 count != 8

234 246
255 Compiles but error at run time

atom granite granite atom granite atom granite

Person[] p = new Person[5]; Person p[5];

world world Compilation fails.

25 Compilation Error
000120 00012021

Compilation fails at line 11 Compilation fails at line 12.

Five Three
If a is false and b is false then the output is If a is false and b is true then the output is
"ELSE" "ELSE"

false 1

compilation error Compiles

Compile error none of the listed options


92 82

Compiles but error at run time None of the listed options

value = 2 value = 8
[608, 610, 612, 629] [608, 610] Compilation fails.

00012021 Compilation error

Compilation fails. The code runs with no output.

Compilation fails. An exception is thrown at runtime.

Vector LinkedList
b = nf.equals( input ); b = nf.parseObject( input );

4 1

2<= r <= 10 3 <= r <= 9

LinkedList is a subclass of ArrayList Stack is a subclass of Vector

There is a syntax error on line 6 There is a syntax error on line 1

NumberFormatException at run time Compiles but no output


No, Runtime error Yes, 100, 100

5,5 6,6

s = s + s * i; s *= i;

Character has a intValue() method Byte extends Number

headSet HeadSet
four one three two one two three four one

Compiles but error at run time None of the listed options

The Map interface extends the Collection


All keys in a map are unique
interface

retriever Compilation fails.

Compilation error null 0


bat man spider man spider man

If a variable of type int overflows during the


A loop may have multiple exit points execution of a loop, it will cause an
exception

Compilation Error 10

tall tall short

4211 3211
compiler error runtime error

compilation error brownie

You win the prize You lose the prize.

The code will compile correctly and display the The code will compile correctly and display
letter a,when run the letter b,when run
22 23

OutputStream is the abstract superclass of all


Subclasses of the class Reader are used to
classes that represent an outputstream of
read character streams.
bytes.

default default apple

3 and 5 4 and 6
Virat Kohli M.S.Dhoni Sachin Virat Kohli

compiler error success

compilation error 40

Compilation fails. collie harrier


Prints: false, true, false Prints: false, true, true

2 23

3 11
An exception occurs at runtime. pi is bigger than 3. Have a nice day.

j=0 j=1

compile error bad

6,5 6,6
Integer, int int, Integer

_score.pack.__pack [email protected]@ckage.innerp@ckage

Java Database Connectivity (JDBC) Java Debugger

Holds the location of User Defined classes,


Holds the location of Java Software
packages and JARs

String [][]args String args

Packages can contain non-java elements such Sub packages should be declared as
as images, xml files etc. private in order to deny importing them

Object class has the core methods for thread Object class provides the method for Set
synchronization implementation in Collection framework

Helps Javadoc to build the Java


Helps JVM to find and execute the classes
Documentation easily

will create two child threads and display Hi


will not create any child thread
twice

new Runnable(MyRunnable).start(); new Thread(new MyRunnable()).start();


will display Hi once compilation error

Compilation error will print Hi once

public class MyRunnable extends Object{public public class MyRunnable implements


void run(){}} Runnable{public void run(){}}
Does not compile Throws exception at runtime

terminate() wait()
Interrupt class Object class

Compiles but throws run time Exception a1 is not a Thread

will not print will start two thread


It prints "Thread one. Thread two." The output cannot be determined.

The output could be 6-1 5-2 6-2 5-1 The output could be 6-1 6-2 5-1 5-2

The code executes normally and prints


An exception is thrown at runtime.
"run".
Only B and C is TRUE All are FALSE

construct(); run();

Implement java.lang.Runnable and implement Extend java.lang.Thread and override the


the run() method run() method.

The code executes normally and prints "Good


prints Good Day.. Twice
Day.."

After the lock on B is released, or after two


Two seconds after lock B is released.
seconds.

Only A is TRUE Both A and B are FALSE

CLASS RUNTIME
@include all the listed options
Depricated Documented

source runtime

Compile time and deploytime processing Runtime processing


Inheritance Identity
Code flexibility at runtime avoiding method name confusion at runtime
Tea -Cup Driver -Car
void add(int x,int y) void sum(double
void add(int x,int y) char add(char x,char y)
x,double y)
Instantiation Segmentation
An Error that might be thrown in a method Except in case of VM shutdown, if a try
must be declared as thrown by that method, or block starts to execute, a corresponding
be handled within that method. finally block will always start to execute.

End of method. run.


run java.lang.RuntimeException: Problem
java.lang.RuntimeException: Problem

Code output: Start Hello world File Not Found The code will not compile.

No code is necessary throws RuntimeException


NumberFormatException thrown at runtime

catch(X x) can catch subclasses of X where X


The Error class is a RuntimeException.
is a subclass of Exception.

One Catch Finally One Two Catch

finally null

The notify() method is defined in class The notify() method causes a thread to
java.lang.Thread immediately release its locks.

NullPointerException ArrayIndexOutOfBoundsException
An exception is thrown at runtime. none

The program will throw an If run with one arguments,the program will
ArrayIndexOutOfBoundsException simply print the given argument

does not compile compiles successfully

Arithmetic Exception compilation error

Variables can be protected from concurrent


access problems by marking them with the When a thread sleeps, it releases its locks
synchronized keyword.
An empty catch block is not allowed A catch block cannot follow a finally block

Exception all of these

Compilation fails exit

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


Thread t = new Thread(X); t.start();
t.start();

Implement java.lang.Thread and implement the Extend java.lang.Runnable and override the
start() method. start() method.
2, 4, 5 and 6 2, 3, 4 and 5

static methods do not have direct access to


static methods are always public, because they
non-static methods which are defined inside
are defined at class-level.
the same class.

IllegalStateException IllegalArgumentException

join() start()

Finally Block Try Block Finally Block

Compilation fails An exception is thrown at runtime.


Compilation fails Compiles but exception at runtime

test exception runtime end test exception end

Exception occurred RuntimeException does not compile

A thread will resume execution as soon as its The notify() method is overloaded to accept
sleep duration expires. a duration
Cannot determine output. Compilation Error

NoClassDefFoundError NumberFormatException

final private
hello throwit RuntimeException caught after hello throwit caught finally after

Compiles but error at run time

Compilation fails Compiles but exception at runtime


Bothe A and B is TRUE Both A and B is FALSE

The program will print Hello world, then will The program will print Hello world, then will
print that a RuntimeException has occurred, print Finally executing, then will print that a
and then will print Finally executing. RuntimeException has occurred.

We cannot have a try block block without a


Nothing is diaplayed
catch / finally block

A ParseException is thrown by the parse A NumberFormatException is thrown by the


method at runtime. parse method at runtime.
The program will only print 1 ,4 and 5 in
The program will only print 1,2 and 4 in order
order

Declaring the doThings() method as static


Compilation fails.
would make the class thread-safe.

Statement 1 is TRUE but Statement 2 is


Both Statement 1 & Statement 2 are TRUE.
FALSE.
Thread t = new Thread(); x.run(); Thread t = new Thread(X); t.start();

X, followed by an Exception, followed by B. none

1, 2, 6 2, 3, 4
hello throwit RuntimeException caught after Compilation fails

Clean compile and at run time the values 0 to 9


Clean compile but no output at runtime
are printed out
Compilation fails with an error on line 7 Compilation fails with an error on line 8

compilation fails ArithmeticException

Compilation fails because of an error in line


Compilation fails because of an error in line 20.
14.
reads data from file named jlist.lst in byte form
Compiles but error at runtime
and display garbage value

reads data from file named jlist.lst in byte form


Compiles but error at runtime
and display garbage value

The program will compile and print H|e|l|l|o|End The program will compile, print H|e|l|l|o|,
of stream. and then terminate normally.
I am a Person I am a Student I am a Student I am a Person

Compiles and runs without output Compiles but error at runtime

reads data from file named jlist.lst in byte form


Compiles but error at runtime
and display garbage value

C,D A,B

the state of the object s1 will not be store to


Compiles but error at run time
the file.
reads data from file named jlist.lst in byte form
Compiles but error at runtime
and ascii value

throws a ArrayIndexOutOfBoundsException returns null

A instance of MyClass and an instance of


An instance of MyClass is serialized
Tree are both serialized

write() writeDouble()

FileOutputStream fos = new


DataOutputStream dos = new
FileOutputStream( new
DataOutputStream( "myData.stuff" )
BufferedOutputStream( "myData.stuff") )

The file is modified from being unwritable to


The boolean value true is returned
being writable.

The file system has a directory named dir, The file system has a directory named
containing a file f1.txt newDir, containing a file f1.txt
writes data to the file in character form. Compiles but error at runtime

Compiles and executes but directories are


Compiles but error at run time
not created

Compiles and runs but content not transferred


Compiles but error at runtime
to the temp.txt

the state of the object s1 will not be store to


Compiles but error at run time
the file.
ab cd abcd

Compiles and executes but directory is not


Compiles but error at run time
created

s.defaultWriteObject(); s.writeObject(x);

Only B is TRUE Both A and B is TRUE

Only B is TRUE Both A and B is TRUE

ResultSet Interface Statement Interface

PreparedStatement RowSet

execute() executeQuery()
Both A and C is TRUE All are TRUE

Either forName() or registerDriver() None of the given options

It returns int value as mentioned below: > 0 if


many columns Contain Null Value < 0 if no
none of the listed options
column contains Null Value = 0 if one column
contains Null value

1) Driver 2) Connection 3) ResultSet 4)


ResultSetMetaData 5) Statement 6)
All of the given options
PreparedStatement 7) Callablestatement 8)
DataBaseMetaData

Line 13 creates a directory named “c” in the


Line 13 creates a File object named “c”
file system.
java.sql.DriverManager java.sql.Connection

Compiles but error at run time Compiles but no output

Read only, Scroll Sensitive Updatable, Scroll sensitive

Compiles but error at run time Compiles but run without output

will show city Compiles but error at run time

java.sql.Driver java.sql.DriverManager java.sql.DataSource

DatabaseMetaData.getMaxConnections ResultSetMetaData.getMaxConnections

execute() executeQuery()
registerDriver() method and Class.forName() getConnection

Implementation Access specifier

public,friend final,protected

display method display method 20 20 super class method display method 10 10


Compilation error None of the listed options

Constructor Destructor

None of the listed options private

sub class show method super class show


Compilation Error
method
III I & III

All members of abstract class are by default Protected is default access modifier of a
protected child class

Compilation error None of the listed options


Constructor is a special type of method which Constructors should be called explicitly like
may have return type. methods

2&3 1&2&4
Child Parent Child

2&3 3&4

static abstract
WD 500 Compile Error.
20 10 10 20
public void bM2(){} All of the listed options
public void aM1(){} public void aM2(){} public
public void aM1(){} public void bM2(){}
void bM1(){} public void bM2(){}

they're not equal t1's an Object No Output Will be Displayed

Statement I is FALSE & II is TRUE Statement I & II are FASLE

Statement I is FALSE & II is TRUE Statement I & II are FASLE


Runtime Exception No Output will be displayed

60,60,60 120, 120, 120


DigiCam do Charge Runtime Error

This class must also implement the hashCode The code will compile as Object class's
method as well. equals method is overridden.

Statement I is FALSE & II is TRUE Statement I & II are FASLE


Generic Polymorphic

It will print 5 None of the listed options


Code will compile but wont print any message Runtime Exception

Statement I is FALSE & II is TRUE Statement I & II are FASLE


2&3 3&4

System.out.gc(); System.gc();

Statement B alone Neither Statements A nor B

line 5 line 1
Statement A is false and Statement B is true Both Statements A and B are false

Option 1 Option 4

scope resolution none of these

compilation error None of the listed options

4 2

finally access
4 Compilation error

13,13,0 12,13,-1

throwed Integer

print main

I->III->IV->II I->II->III->IV
The code executes normally, but nothing is
Compilation fails.
printed.

Important job running in MyThread String in


String in run
run
Runtime Exception Non of the options

Compilation will cause an error because


The code will cause an error at compile time.
while cannot take a parameter of true.

BOTH Statement1 & Statement2 are


BOTH Statement1 & Statement2 are TRUE.
FALSE.
The code executes and prints
The code executes and prints "Runner".
"RunnerRunnerRunner".

The delay between “Start!” being printed and If “Time’s Over!” is printed, you can be sure
“Time’s Over!” will be 10 seconds plus or minus that at least 10 seconds have elapsed since
one tick of the system clock. “Start!” was printed.

Dead Blocked

2&3 1&4

boolean getPriority() boolean isAlive()

Three Four
notifyAll() all the options

Synchronized classes Synchronized abstract classes


Requires less overheads compared to
Increase system efficiency.
multitasking.

Compilation error [abc]

2&3 1&4

SortedList SortedQueue

Prints the output [Green World, Green


Throws Runtime Exception
Peace] at line no 9
Object String

Creates a Date object with current date and Creates a Date object with current date
time as default value alone as default value

The ListIterator interface provides the ability to The ListIterator interface provides forward
determine its position in the List. and backward iteration capabilities.

Object set1

In Line 4 null pointer exception will occur as


Line 4 has neither error nor exceptions.
String string contains null value
Collection Sorted Map

java.util.Dictionary java.util.HashMap

SortedSet Comparable

The elements in the collection are accessed


HashSet allows at most one null element
using a unique key.

All implementations are serializable and all implementations are immutable and
cloneable supports duplicates data

foreach Iterator

Statement A is false and Statement B is true Both the statements A and B are false.
C D

None of the listed options

2&3 1&4

Statement A is false and Statement B is true Both Statements A and B are false

compareTo compareWith
compilation error Runtime error

false false true false

Strings cannot be compare using ==


compilation error
operator
Statement I is FALSE & II is TRUE Statement I & II are FASLE

Statement I is FALSE & II is TRUE Statement I & II are FASLE

Extracting strings All of above

x = Rules x = Java
Strings cannot be compare using ==
compilation error
operator

6 None of the listed options

x = Java x="JAVA"
1&3 2

compilation error None of the listed options


Runtime error None of the listed options

1&3&4 1&2&4
throws Exception No code is necessary.

Demands a finally block at line number 4 Demands a finally block at line number 5

NoClassDefFoundError is a subClass of
None of the options
ClassNotFoundException

throw RuntimeException

finally block will be always executed in any


The death of the thread
circumstances.

2&3 1&4
Both catch block and finally block can throw
All of the listed options
exceptions

Compile Time Exception Runtime Exception

compilation error
hello Math problem occur string problem occur
hello string problem occur stopped
problem occurs stopped

throw throwable

Compilation error None of the listed options

RunTimeException FileNotFindException

thrown catch
Compile time error Cannot use Throwable to Run time error test() method does not throw
catch the exception a Throwable instance

finally finally exception finished

RunTimeException are the exceptions


RuntimeException is a class of I/O exception which forces the programmer to catch them
explicitly in try-catch block
2&3 1&4

after switching from try block to catch block


catch block is not mandate always only finally
the control never come back to try block to
followed by try can be executed
execute rest of the code

Checked exceptions are the object of the


All runtime exceptions are checked
Exception class or any of its subclasses except
exceptions
Runtime Exception class.

A,C Runtime error

Statement A is false and Statement B is true Both Statements A and B are false

ClassNotFoundException Number Format Exception

SQLException NullPointerException
statement 1:false statement2:false statement 1:true statement2:false

ObjectFilter FileFilter

Reader OutputStream

system compilation error

As bytes from the stream are read or


skipped, the internal buffer is refilled as
it has flush() method
necessary from the contained input stream,
many bytes at a time.

Externalizable None of the listed options


File String

1&3&4 1&2&4

12 None of the listed options

break label

code will execute with out printing runtime Exception


Compilation error Runtime Exception

4 8

Both by value & reference none of these

while do …. While

Compilation error Runtime Exception

Runtime Error compiles and prints 12

compilation error None of the listed options


Compilation error 10.987

6,0 0,5

91,97 97,91

exit goto

Primitive Wrapper Primitive


The number 3 gets printed with
The number 2 gets printed with AssertionError
AssertionError

continue new

execute() noexecute()

PreparedStatement Condition

2&3 1&4

ParameterizedStatement and All kinds of Statements (i.e. which


CallableStatement implement a sub interface of Statement)

Connection Connection
cn=DriverManager.getConnection("jdbc:odbc cn=DriverManager.getConnection("jdbc:odb
","username", "password"); c:dsn" ,"username", "password");

Connection() getConnetion()

Type 3 driver Type 4 driver


"SELECT * FROM Person" query must be
Class.forName must be mentioned after
passed as parameter to
Connection statement
con.createStatement()

Both A and B None of the above

execute() noexecute()

pkg.sql java.sql

paused stopped

java.sql.Time java.sql.Timestamp

Call method execute() on a StoredProcedure Call method run() on a ProcedureCommand


object object

TableStatement Condition
DDL statements cannot be executed by
Support for DDL statements will be a
making use of JDBC, you should use the
feature of a future release of JDBC
native database tools for this.

ODBC written in C++ language ODBC written in Basic language

Statement A is False and Statement B is True. Both Statements A and B are False.

java.sql and javax.sql java.rdb and javax.rdb

setString() setToString()

CallableStatement None of the listed options

java.util.List java.util.ArrayList

DataSource Statement

Collection APIs None of the listed options


LinkedHashMap Non of the listed options

CallableStatement None of the listed options

Reduces effort to learn and to use new APIs Fosters software reuse

If the hashCode() comparison == returns true, If the hashCode() comparison == returns


the equals() method must return true true, the equals() method might return true

Declare the ProgrammerAnalyst class has final None of the listed options

Synchronization Deserialization

A thread can exist only in two states,


Two thread in Java can have same priority
running and blocked.

Using object deserialization None of the listed options

static block code private method


Check whether you have marked Customer
None of the listed options
class methods with synchronized keyword

java.lang.StringBuffer java.lang.Character

None of them will be executed It is dependent on the operating system.

When designing your own collections class


(say, a linked list), generics and parameterized
types allow you to achieve type safety with just All of the mentioned
a single class definition as opposed to defining
multiple classes.

Make Employee class methods private Make Employee class methods public

java.util.List java.util.Collection

Implement using file API’s None of the listed options


Grad Grad
Choice5 Grade Grade Grade5
e1 e2

0 0 0 1

0 0 0 1

0 1 0 0

0 0 1 0

0 0 0 1
0 0 1 0

0 1 0 0

0 0 1 0
0 0 0 1

0 1 0 0

1 0 0 0
0 0 0 1

1 0 0 0

0 0 0.5 0.5

1 0 0 0

0 0 1 0

1 0 0 0
0 1 0 0

0 0 1 0

0 1 0 0

this.suns = planets; 0.33 0.33 0 0 0.33


0 1 0 0

1 0 0 0
0 0 1 0

0 0 0 1
1 0 0 0

1 0 0 0

1 0 0 0
0 1 0 0

0 1 0 0

1 0 0 0

1 0 0 0

0 0 1 0
1 0 0 0

0 1 0 0

0 0 1 0

0 0 1 0
1 0 0 0

0 0 0 1

1 0 0 0

0 0 1 0

0 0 0 1
1 0 0 0

0 0 0 1

0 1 0 0

1 0 0 0

1 0 0 0

0 0 0 1
0 0 1 0

0 1 0 0

0 1

1 0 0 0

1 0 0 0
1 0 0 0

1 0 0 0

0 0 0 1

0 0 1 0
0 1 0 0

0 1 0 0

private final static int answer =


0.25 0 0.25 0.25 0.25
42;

0 1 0 0

0 1 0 0
0 0 1 0

0 1 0 0

0 0 1 0

abstract class Vehicle { abstract


0 0 0 0 1
void display(); }

1 0 0 0

0.5 0 0.5 0
0 0 0 1

0 1 0 0

0 0 0 1

0 1 0 0

0.5 0.5 0 0

public static MAIN = 15; 0 0.5 0 0.5 0


0 0 1 0

0 0 1 0

0 0 1 0

The overriding method must


have different return type as 1 0 0 0 0
the overridden method
0 1 0 0

0 0 0 1

0 0 0 1

0 1 0 0
Calling super() as the first
statement in the body of a
constructor of a subclass will
0 1 0 0 0
always work, since all
superclasses have a default
constructor.

1 0 0 0

0 1 0 0

0 0 0 1

0 1 0 0
0 0 0 1

0 1 0 0

1 0 0 0

1 0 0 0

0.333 0 0.333 0.333

0 0 1 0
0 0 0 1

0 0 1 0

0 0 0 1
0 0 1 0

0 1 0 0

0 0 0 1

The statement b.i = 3; is legal. 0.333 0.333 0 0.333 0


0 0 0 1

0 0 1 0

1 0 0 0

0 0 1 0

0 0 1 0
0 0 1 0

0 0 0 1
0 1 0 0

0 1 0 0

0 0 1 0

The size of subs is 1 0 0.5 0.5 0 0

java.util.Vector 0 0 0 1 0
0 0 1 0

0 0 0 1

0 0 1 0

0 1 0 0

0 0 1 0

1 0 0 0
0 1 0 0

0 0 0 1

0 0 1 0

0 1 0 0
0 1 0 0

0 1 0 0

0 0 1 0

0 0 0 1

0 0 1 0

0 0 1 0
0 0 1 0

1 0 0 0

0 0 1 0

0 0 1 0

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

0 1 0 0

0 0 0 1
Compilation fails because of an
1 0 0 0 0
error in line 23.

0 0 1 0

0 1 0 0

0 0 1 0

0 0 1 0

1 0 0 0
0 0 0 1

0 0 1 0

1 0 0 0

0 1 0 0

0 0 1 0

1 0 0 0

0 0 1 0
Compilation error 0 0 0 1 0

1 0 0 0

0 0 0 1

none of the listed options 0 1 0 0 0


0 0 0 1

1 0 0 0

0 1 0 0

0 1 0 0

0 0 0 1
0 0 0 1

0 0 1 0

0 0 0 1

0 1 0 0
Dog myDogs [7]; 0.333 0.333 0 0.333 0

Runtime Error 0 0 0 1 0
1 0 0 0

0 1 0 0

1 0 0 0

0 1 0 0

0 0 1 0
0 0 0 1

0 0 1 0

0 1 0 0

1 0 0 0

0 0 0.5 0.5

Line 4 0 1 0 0 0

1 0 0 0
0 1 0 0

1 0 0 0

1 0 0 0

0 1 0 0

0 0 0 1
0 0 0 1

0 1 0 0

A.this.doIt() 1 0 0 0 0

0 0 1 0
0 1 0 0

1 0 0 0

0 0 0 1

0 1 0 0

0 1 0 0

1 0 0 0

1 0 0 0
1 0 0 0

0 0 1 0

0 0 1 0

0 0 0 1

1 0 0 0

0 1 0 0
0 0 1 0

if(s.equalIgnoreCase(s2)) 0 0 1 0 0

The second line of output is


0 0 0.5 0 0.5
abcd abcd true

0 1 0 0
0 0 1 0

0 0 0 1

0 0 0 1

0 0 0 1

0 1 0 0

0 0 1 0

1 0 0 0
0 0 1 0

1 0 0 0

1 0 0 0

The program will print


0 0 0 1 0
str3str2,when run

1 0 0 0

1 0 0 0
0 0 1 0

0 0 1 0

0 0 0 1

none of the listed options 0 0 0 1 0


0 1 0 0

Set all references to the object


to new values(null, for 1 0 0 0 0
example).

The garbage collector will use a


0 0 0.5 0.5 0
mark and sweep algorithm

1 0 0 0

0 1 0 0
0 0 1 0

0 0 0 1

0 0 0 1

0 0 0 1

Runtine Error 0 0 1 0 0
0 0 1 0

0 0 1 0

1 0 0 0
0 0 0 1

0 0 1 0

0 1 0 0

0 0 1 0
0 0 0 1

0 1 0 0

0 0 0 1
1 0 0 0

0 1 0 0

0 0 1 0

0 0 1 0

ArrayList 0 0 0 1 0
0 1 0 0

0 0 0 1

1 0 0 0

0.5 0 0 0.5

0 0 1 0

0 0 1 0
0 0 0 1

0 0 1 0

Compilation error 0 0 0 1 0

String is the wrapper class of


0 0.5 0 0.5 0
char

1 0 0 0
0 0 1 0

0 1 0 0

All Map implementations keep


0 0.5 0 0.5 0
the keys sorted

0 0 0 1

0 1 0 0
0 0 1 0

0 0 1 0

Runtime Error 0 0 1 0 0

short 0 0 0 1 0

0 1 0 0
0 0 1 0

0 0 0 1

0 0 1 0

The code will compile


correctly,but will not display any 0 0 0 1 0
output
24 0 0 1 0 0

0 0 0.5 0.5

0 1 0 0

0 1 0 0
1 0 0 0

0 0 1 0

0 0 0 1

0 0 0 1
0 0 1 0

0 0 0 1

7 0 0 0 1 0
1 0 0 0

1 0 0 0

0 0 1 0

0 1 0 0
0 1 0 0

.
package.subpackage.innerpack 0.333 0.333 0.333 0 0
age
0 1 0 0

0 0 1 0

String[] args[] 0.5 0.5 0 0 0

Class and Interfaces in the sub


packages will be automatically
0 0.5 0.5 0 0
available to the outer packages
without using import statement.

Object class implements


0 0 0.5 0.5 0
Serializable interface internally

0 1 0 0

0 0 1 0

0 0 0 1
1 0 0 0

0 1 0 0

0 0 0 1
1 0 0 0

start() 0.5 0 0 0 0.5


0 0 0 1

0 0 0 1

1 0 0 0
0 1 0 0

0 0 0 1

0 0 1 0
0 0 1 0

1 0 0 0

Extend java.lang.Runnable and


0 0 0.5 0.5 0
override the start() method.

0 0 1 0

1 0 0 0

0 1 0 0

CONSTRUCTOR 0 0.333 0.333 0.333 0


1 0 0 0
Target 0 0.333 0 0.333 0.333
0 1

0 1 0 0

Information for the OS 0.333 0 0.333 0.333 0


0 0 0 1
0 0 1 0
1 0 0 0
0 0 1 0
0 0 0 1
0 0 0 1

0 0 1 0

0 0 0 1

0 1 0 0
1 0 0 0

0 0 1 0

0 0 1 0

1 0

0 1 0 0

1 0 0 0

0 1 0 0
1 0 0 0

0 1 0 0

0 1 0 0

0 0 1 0

0 1 0 0
A finally block must always
0 0 0 1 0
follow one or more catch blocks

0 1 0 0

0 1 0 0

0 0 1 0

Implement java.lang.Thread
and implement the run() 0.5 0.5 0 0 0
method.
1 0 0 0

0 0.5 0 0.5

0 0.5 0 0.5

0.5 0.5 0 0

1 0 0 0

peep 0 0 0 1 0
0 0 0 1

0 0 0 1

0 0 0 1

Both wait() and notify() must be


called from a synchronized 0 0.33 0.33 0 0.33
context.
1 0 0 0

0 0 0 1

0 1 0 0
0 0 0 1

0 0 1 0

0 0 1 0
0 0 1 0

0 0 0 1

1 0

0 0 1 0

0 1 0 0
The program will only print
0 0 0 1 0
1,2,4 and 5 in order

0 0 0 1

0 0 1 0
1 0 0 0

1 0 0 0

0 0 1 0
1 0 0 0

0 0 0 1
Compilation fails with an error
0 0 0 0.5 0.5
on line 9

0 0 1 0

0 0 0 1
0 1 0 0

1 0 0 0

0 0 0 1
0 1 0 0

1 0 0 0

1 0 0 0

0 0 0 1

0 0 1 0
0 0 1 0

0 1 0 0

1 0 0 0

0 0 0 1

0 1 0 0

none of the listed options 0 1 0 0 0

Compilation error 0 0 0 1 0
1 0 0 0

0 0 0 1

0 0 1 0

1 0 0 0
Compilation Error 0 0 0 0 1

1 0 0 0

0 0 1 0

1 0 0 0

0 0 0 1

PreparedStatement Interface 1 0 0 0 0

0 0 1 0

0 0 1 0
1 0

0 0 0 1

0 0 1 0

0 1 0 0

0 0 1 0

0 0.5 0.5 0

1 0
1 0 0 0

0 0 1 0

1 0 0 0

0 0 1 0

0 0 0 1

0 0 1 0

0 0 1 0

executeUpdate() 0 0 1 0 0

1 0
0 0 1 0

Class 0 0 0 1 0

private,abstract 0 1 0 0 0

0 1 0 0
0 0 1 0

0 1

1 0

Variable 0 0 1 0 0

0 1 0 0

1 0 0 0
1 0 0 0

1 0

1 0 0 0

1 0 0 0
1 0 0 0

1 0

1 0

2&4 0 0 0 1 0
0 0 1 0

2&4 0 0 0 0 1

1 0

0 1

1 0 0 0
0 0 1 0

1 0
0 1 0 0

1 0

0 1

1 0
0 1

1 0

0 1
0 1

0 0 0 1
0 0 1 0

0 0 1 0

1 0 0 0

1 0

1 0 0 0
0 1 0 0

0 0 0 1
1 0 0 0

1 0 0 0

1 0 0 0
1 0

1 0 0 0

0 1 0 0
1 0 0 0

1 0 0 0
2&4 0 0 0 0 1

0 0 0 1

1 0 0 0

0 1 0 0
1 0 0 0

0 0 1 0

0 1 0 0

0 0 1 0

0 0 0 1

1 0

exception 0 0 0 0.5 0.5

0 1
0 1 0 0

1 0

0 1 0 0

Boolean 0 0 1 0 0

Object 0 1 0 0 0

1 0 0 0
1 0 0 0

1 0

No Output 0 0 0 0 1
0 1 0 0

0 0 1 0

0 1 0 0

1 0
0 0 0 1

0 0 0 1

Stop 0 0 0 0 1

2&4 0 0 0 1 0

0 0 1 0

0 1 0 0
0 0 0 1

Synchronized interfaces 0.5 0.5 0 0 0

None of the options. 0 0 0 0 1

0 1 0 0

2&4 0 0 0 0 1

0.5 0.5 0 0

0 1

0 0 1 0
0 1

1 0

0 0 1 0

0 0 1 0

0.33 0 0.33 0.33

0 0 1 0

1 0

1 0

0.5 0 0 0.5
0 1

1 0

0 0 0.5 0.5

0 0 0.5 0.5

0 0 0.5 0.5

1 0

0 0.5 0 0.5

0.33 0.33 0.33 0

0 1

0 0 0.5 0.5

0 0 0 1
E 0 0 0 1 0

0 1

0 1

0 1

0 0 0

1 0

2&4 0 1 0 0 0

0 1 0 0

0 0 1 0
1 0

0 1

1 0

1 0 0 0

1 0

1 0

0 1 0 0

0 1 0 0
0 1

1 0 0 0

1 0

0 1 0 0

0 1

0 1

0 0 0 1

0 0 0 1
0 1 0 0

0 1 0 0

0 0 1 0
2&3 1 0 0 0 0

1 0 0 0
0 1 0 0

0 1

2&4 0 0 1 0 0

0 1
1 0

1 0

0 0 1 0

0 0 0 1

0.5 0.5 0 0

0 1

1 0 0 0

0.33 0.33 0 0.33

2&4 1 0 0 0 0
0 0 0 1

1 0

0 0 1 0

0 0 1
0 0 0 1

0 0 1 0

0 1 0 0

0.33 0 0.33 0.33

0.5 0 0 0.5
1 0 0 0

0 0 0 1

0.5 0.5 0 0

1 0

1 0
2&4 0 0 0 0 1

0 0 0.5 0.5

1 0

0.5 0 0.5 0

1 0 0 0

1 0 0 0

0.33 0.33 0 0.33

0 0 0 1
0 1 0 0

1 0

0 0 1 0

1 0

0 0.33 0.33 0.33

0 0 1 0

0 1

1 0

1 0

1 0

0.33 0.33 0.33 0

0 1 0 0
1 0

0 0.5 0.5 0

0 1

0 1

1 0

2&4 0 0 1 0 0

0 1 0 0

branch 1 0 0 0 0

0 1 0 0
1 0 0 0

1 0

64 0 0 0 1 0

1 0 0 0

for..each 0 0 0 1 0

0 0 0 1

1 0 0 0

0 1 0 0
1 0 0 0

0 1 0 0

0 0 0 1

escape 1 0 0 0 0

None Of the options 1 0 0 0 0


The program generates a
0 1 0 0 0
compilation error.

none 0 1 0 0 0

0 1 0 0

0 0 1 0

2&4 0 0 1 0 0

1 0 0 0

0 1 0 0

0 1

0 0 0 1

0 0 0 1
0 1 0 0

0 1 0 0

1 0

0 0 1 0

0 0 0 1

1 0 0 0

0 0 0 1

1 0

1 0 0 0

1 0 0 0
1 0 0 0

1 0

1 0 0 0

1 0 0 0

0 0 1 0

0 0 1 0

0 1 0 0

0 0 0 1

0 1 0 0

1 0

1 0 0 0
1 0 0 0

0 0 1 0

1 0

All of the listed options 0 0 0 0 1

0 0.5 0 0.5

0 0 1 0

0 1 0 0

0 0 0 1

1 0 0 0

0 0 1 0
1 0 0 0

0 0 1 0

0 0 0 1

1 0

0 0 1 0

1 0 0 0

0 1 0 0

0 1 0 0

You might also like