You are on page 1of 309

SubBank QuestionText QuestionType Choice1

What will be the result of compiling the


following program?
public class MyClass {
long var;
public void MyClass(long param) { var = param; A compilation
} // (Line no 1) error will
Access public static void main(String[] args) { occur at (Line
Specifiers MyClass a, b; no 1), since
Constructors a = new MyClass(); // (Line no 2) constructors
Methods } cannot specify
NewQB } MCQ a return value
Access
Specifiers
Constructors
Methods Which of the following declarations are correct? boolean b =
NewQB (Choose TWO) MCA TRUE;

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[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My Func");
Access } The code will
Specifiers public void amethod(){ compile and
Constructors myfunc(); run, printing
Methods } out the words
NewQB } MCQ "My Func"

Constructor of
Access A executes
Specifiers class A, B and C are in multilevel inheritance first, followed
Constructors hierarchy repectively . In the main method of by the
Methods some other class if class C object is created, in constructor of
NewQB what sequence the three constructors execute? MCQ B and C
Consider the following code and choose the
correct option:
Access package aj; private class S{ int roll;
Specifiers S(){roll=1;} }
Constructors package aj; class T
Methods { public static void main(String ar[]){ Compilation
NewQB System.out.print(new S().roll);}} MCQ error

Here is the general syntax for method


definition:
The
accessModifier returnType returnValue
methodName( parameterList ) can be any
{ type, but will
Java statements be
automatically
return returnValue; converted to
Access } returnType
Specifiers when the
Constructors method
Methods What is true for the returnType and the returns to the
NewQB returnValue? MCQ caller
Access
Specifiers A) A call to instance method can not be made
Constructors from static context.
Methods B) A call to static method can be made from Both are
NewQB non static context. MCQ FALSE

Consider the following code and choose the


Access correct option:
Specifiers class A{ A(){System.out.print("From A");}}
Constructors class B extends A{ B(int z){z=2;}
Methods public static void main(String args[]){ Compilation
NewQB new B(3);}} MCQ error
class Sample
{int a,b;
Sample()
{ a=1; b=2;
System.out.println(a+"\t"+b);
}
Sample(int x)
{ this(10,20);
a=b=x;
System.out.println(a+"\t"+b);
}
Sample(int a,int b)
{ this();
this.a=a;
this.b=b;
System.out.println(a+"\t"+b);
}
}
class This2
{ public static void main(String args[])
Access {
Specifiers Sample s1=new Sample (100);
Constructors }
Methods } 100 100 1 2
NewQB What is the Output of the Program? MCQ 10 20

Consider the following code and choose the


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

Consider the following code and choose the


Access correct option:
Specifiers package aj; class A{ protected int j; }
Constructors package bj; class B extends A code compiles
Methods { public static void main(String ar[]){ fine and will
NewQB System.out.print(new A().j=23);}} MCQ display 23

Consider the following code and choose the


Access correct option:
Specifiers class A{ int z; A(int x){z=x;} }
Constructors class B extends A{
Methods public static void main(String arg){ Compilation
NewQB new B();}} MCQ error
class Test{
static void method(){
this.display();
}
static display(){
System.out.println(("hello");
}
public static void main(String[] args){
Access new Test().method();
Specifiers }
Constructors }
Methods consider the code above & select the proper
NewQB output from the options. MCQ hello

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

public class Pri extends Base{


static int i = 200;
Access public static void main(String argv[]){
Specifiers Pri p = new Pri();
Constructors System.out.println(i);
Methods }
NewQB } MCQ 200

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

Access public static void main(String[] args) {


Specifiers print("String first", 11); String: String
Constructors print(99, "Int first"); first, int: 11 int:
Methods } 99, String: Int
NewQB }What would be the output? MCQ first
A) No argument constructor is provided to all
Java classes by default
B) No argument constructor is provided to the
Access class only when no constructor is defined.
Specifiers C) Constructor can have another class object
Constructors as an argument
Methods D) Access specifiers are not applicable to Only A is
NewQB Constructor MCQ TRUE

Consider the following code and choose the


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

Which of the following sentences is true?


A) Access to data member depends on the
scope of the class and the scope of data
Access members
Specifiers B) Access to data member depends only on the
Constructors scope of the data members
Methods C) Access to data member depends on the Only A and C
NewQB scope of the method from where it is accessed MCQ is TRUE

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) {
short y = 6;
long z = 7;
Access go(y);
Specifiers go(z);
Constructors }
Methods }
NewQB What is the result? MCQ int Long
Access
Specifiers
Constructors System.out.pri
Methods ntln(Math.ceil(
NewQB Which of the following will print -4.0 MCQ -4.7));
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
B) If class A has parameterized constructor,
Access then class B can have default as well as
Specifiers parameterized constructor
Constructors C) If class A has parameterized constructor
Methods then call to class A constructor should be made Only B and C
NewQB explicitly by constructor of class B MCQ is TRUE

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

Consider the following code and choose the


Access correct option:
Specifiers class A{ private void display() Compiles but
Constructors { System.out.print("Hi");} doesn't
Methods public static void main(String ar[]){ display
NewQB display();}} MCQ anything

Consider the following code and choose the


correct option:
public class MyClass {
public static void main(String arguments[]) {
amethod(arguments);
}
public void amethod(String[] arguments) {
Access System.out.println(arguments[0]);
Specifiers System.out.println(arguments[1]);
Constructors }
Methods }
NewQB Command Line arguments - Hi, Hello MCQ prints Hi Hello
package QB;
class Sphere {
protected int methodRadius(int r) {
System.out.println("Radious is: "+r);
return 0;
}
}
package QB;
public class MyClass {
public static void main(String[] args) {
double x = 0.89;
Access Sphere sp = new Sphere();
Specifiers // Some code missing
Constructors }
Methods } to get the radius value what is the code of line methodRadius
NewQB to be added ? MCQ (x);

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

Consider the following code and choose the


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

Consider the following code and choose the


best option:
Access class Super{ int x; Super(){x=2;}}
Specifiers class Sub extends Super { void displayX(){
Constructors System.out.print(x);}
Methods public static void main(String args[]){ Compilation
NewQB new Sub().displayX();}} MCQ error
class One{
int var1;
One (int x){
var1 = x;
}}
class Derived extends One{
int var2;
Derived(){
super(10);
var2=10;
}
void display(){
System.out.println("var1="+var1+" ,
var2="+var2);
}}
class Main{
public static void main(String[] args){
Access Derived obj = new Derived();
Specifiers obj.display();
Constructors }}
Methods consider the code above & select the proper var1=10 ,
NewQB output from the options. MCQ var2=10

public class MyAr {


static int i1;
public static void main(String argv[]) {
MyAr m = new MyAr();
m.amethod();
}
Access public void amethod() {
Specifiers System.out.println(i1);
Constructors }
Methods }
NewQB What is the output of the program? MCQ
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:
System.out.println("zero");
break;
case 1:
System.out.println("one");
Access case 2:
Specifiers System.out.println("two");
Constructors }
Methods } Compilation
NewQB } MCQ Error

Which statements, when inserted at (1), will not


result in compile-time errors?
public class ThisUsage {
int planets;
static int suns;
Access public void gaze() {
Specifiers int i;
Constructors // (1) INSERT STATEMENT HERE
Methods } i=
NewQB } MCA this.planets;
Access
Specifiers
Constructors
Methods Which modifier is used to control access to
NewQB critical code in multi-threaded programs? MCQ default
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()");
}
}
class PortableLunch extends Lunch {
PortableLunch() {
System.out.println("PortableLunch()");
}
}
class Sandwich extends PortableLunch {
private Cheese c = new Cheese();

public Sandwich() {
System.out.println("Sandwich()");
}
}
Access public class MyClass7 { Meal()
Specifiers public static void main(String[] args) { Lunch()
Constructors new Sandwich(); PortableLunch
Methods } () Cheese()
NewQB } What would be the output? MCQ Sandwich()

Consider the following code and choose the


correct option:
class A{ int a; A(int a){a=4;}}
Access class B extends A{ B(){super(3);} void
Specifiers displayA(){
Constructors System.out.print(a);}
Methods public static void main(String args[]){ compiles and
NewQB new B().displayA();}} MCQ display 0
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);
System.out.println(j);
}
Error:
Access public void amethod(int x){ amethod
Specifiers x=x*2; parameter
Constructors j=j*2; does not
Methods } match
NewQB } MCQ variable

The compiler
will
Access automatically
Specifiers change the
Constructors What will happen if a main() method of a private
Methods "testing" class tries to access a private instance variable to a
NewQB variable of an object using dot notation? MCQ public variable

11. class Mud {


12. // insert code here
13. System.out.println("hi");
14. }
15. }
And the following five fragments:
public static void main(String...a) {
public static void main(String.* a) {
Access public static void main(String... a) {
Specifiers public static void main(String[]... a) {
Constructors public static void main(String...[] a) {
Methods How many of the code fragments, inserted
NewQB independently at line 12, compile? MCQ
class Order{
Order(){
System.out.println("Cat");
}
public static void main(String... Args){
Order obj = new Order();
System.out.println("Ant");
}
static{
System.out.println("Dog");
}
Access {
Specifiers System.out.println("Man");
Constructors }}
Methods consider the code above & select the proper Man Dog Cat
NewQB output from the options. MCQ Ant

abstract class MineBase {


abstract void amethod();
static int i;
}
public class Mine extends MineBase {
public static void main(String argv[]){
Access int[] ar=new int[5];
Specifiers for(i=0;i < ar.length;i++) A Sequence
Constructors System.out.println(ar[i]); of 5 zero's will
Methods } be printed like
NewQB } MCQ 00000

public class Q {
Access public static void main(String argv[]) { Compiler
Specifiers int anar[] = new int[] { 1, 2, 3 }; Error: anar is
Constructors System.out.println(anar[1]); referenced
Methods } before it is
NewQB } MCQ initialized
Access
Specifiers
Constructors
Methods A constructor may return value including class
NewQB type MCQ true

Consider the following code and choose the


correct option:
Access package aj; class S{ int roll =23;
Specifiers private S(){} }
Constructors package aj; class T
Methods { public static void main(String ar[]){ Compilation
NewQB System.out.print(new S().roll);}} MCQ error
public class c123 {
private c123() {
System.out.println("Hellow");
}
public static void main(String args[]) {
c123 o1 = new c123();
c213 o2 = new c213();
}
}
class c213 {
private c213() {
Access System.out.println("Hello123");
Specifiers }
Constructors }
Methods
NewQB What is the output? MCQ Hellow

class MyClass1
{
private int area(int side)
{
return(side * side);
}
public static void main(String args[ ])
{
MyClass1 MC = new MyClass1( );
Access int area = MC.area(50);
Specifiers System.out.println(area);
Constructors }
Methods } Compilation
NewQB What would be the output? MCQ error

public class MyAr {


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

public class c1 {
private c1()
{
System.out.println("Hello");
}
public static void main(String args[])
{
Access c1 o1=new c1();
Specifiers }
Constructors }
Methods
NewQB What is the output? MCQ Hello
Access
Specifiers
Constructors Which modifier indicates that the variable might
Methods be modified asynchronously, so that all threads
NewQB will get the correct value of the variable. MCQ synchronized
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;

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);
Access subOb.show("This is k: "); // this calls show()
Specifiers in B
Constructors subOb.show(); // this calls show() in A
Methods } This is j: 5 i
NewQB } What would be the ouput? MCQ and k: 3 7

Consider the following code and choose the


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

class Order{
Order(){
System.out.println("Cat");
}
public static void main(String... Args){
Order obj = new Order();
System.out.println("Ant");
}
Access static{
Specifiers System.out.println("Dog");
Constructors }}
Methods consider the code above & select the proper
NewQB output from the options. MCQ Cat Ant Dog
What will be the result when you attempt to
compile this program?
public class Rand{
public static void main(String argv[]){
Access int iRand;
Specifiers iRand = Math.random(); Compile time
Constructors System.out.println(iRand); error referring
Methods } to a cast
NewQB } MCQ problem
Annotations_ Choose the meta annotations. (Choose
NewQB THREE) MCA Override
If no retention policy is specified for an
Annotations_ annotation, then the default policy of
NewQB __________ is used. MCQ method
Select the variable which are in
Annotations_ java.lang.annotation.RetentionPolicy class.
NewQB (Choose THREE) MCA SOURCE

Information
Annotations_ Select the Uses of annotations. (Choose For the
NewQB THREE) MCA Compiler

Annotations_ All annotation types should maually extend the


NewQB Annotation interface. State TRUE/FALSE MCQ true
Annotations_
NewQB Custom annotations can be created using MCQ @interface

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:
20. java.util.List<a> list = new
java.util.ArrayList</a>();
21. list.add(new B());
22. list.add(new C());
23. for (A a:list) {
24. a.x(); Compilation
25. a.y();; fails because
Collections_ut 26. } of an error in
il_NewQB What is the result? MCQ line 25
Given:
public static Collection get() {
Collection sorted = new LinkedList();
sorted.add("B"); sorted.add("C");
sorted.add("A");
return sorted;
}
public static void main(String[] args) {
for (Object obj: get()) {
System.out.print(obj + ", ");
}
Collections_ut }
il_NewQB What is the result? MCQ A, B, C,

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>();
list.add(new StringBuilder("B"));
list.add(new StringBuilder("A"));
list.add(new StringBuilder("C")); The program
Collections.sort(list,Collections.reverseOrder()); will compile
System.out.println(list.subList(1,2)); and print the
Collections_ut } following
il_NewQB } MCQ output: [B]

Consider the following code and choose the


correct option:
public static void before() {
Set set = new TreeSet();
set.add("2");
set.add(3);
set.add("1");
Iterator it = set.iterator();
while (it.hasNext()) The before()
Collections_ut System.out.print(it.next() + " "); method will
il_NewQB } MCQ print 1 2

import java.util.StringTokenizer;
class ST{
public static void main(String[] args){
String input = "Today is$Holiday";
StringTokenizer st = new
StringTokenizer(input,"$");
while(st.hasMoreTokens()){
Collections_ut System.out.println(st.nextElement()); Today is
il_NewQB }} MCQ Holiday
Given:
public static Iterator reverse(List list) {
Collections.reverse(list);
return list.iterator();
}
public static void main(String[] args) {
List list = new ArrayList();
list.add("1"); list.add("2"); list.add("3");
for (Object obj: reverse(list))
System.out.print(obj + ", ");
Collections_ut }
il_NewQB What is the result? MCQ 3, 2, 1,

Which collection class allows you to grow or


shrink its size and provides indexed access to
Collections_ut its elements, but its methods are not java.util.Hash
il_NewQB synchronized? MCQ Set

Collections_ut int indexOf(Object o) - What does this method


il_NewQB return if the element is not found in the List? MCQ null

What is the result of attempting to compile and


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

Consider the following code and choose the


correct option:
class Test{
public static void main(String args[]){
Integer arr[]={3,4,3,2};
Set<Integer> s=new
TreeSet<Integer>(Arrays.asList(arr));
s.add(1);
Collections_ut for(Integer ele :s){ Compilation
il_NewQB System.out.println(ele); } }} MCQ error
Inorder to remove one element from the given
Treeset, place the appropriate line of code
public class Main {
public static void main(String[] args) {
TreeSet<Integer> tSet = new
TreeSet<Integer>();
System.out.println("Size of TreeSet : " +
tSet.size());
tSet.add(new Integer("1"));
tSet.add(new Integer("2"));
tSet.add(new Integer("3"));
System.out.println(tSet.size());
// remove the one element from the Treeset
System.out.println("Size of TreeSet after
removal : " + tSet.size());
Collections_ut } tSet.clear(new
il_NewQB } MCQ Integer("1"));

Consider the code below & select the correct


ouput from the options:
public class Test{
public static void main(String[] args) {
String
[]colors={"orange","blue","red","green","ivory"};
Arrays.sort(colors);
int s1=Arrays.binarySearch(colors, "ivory");
Collections_ut int s2=Arrays.binarySearch(colors, "silver");
il_NewQB System.out.println(s1+" "+s2); }} MCQ 2 -4

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");
hm.put(1,"One");
hm.put(6,"Six");
hm.put(7,"Seven");
SortedMap<Integer, String>
sm=hm.subMap(2,7);
SortedMap<Integer,String> {2=Two,
sm2=sm.tailMap(4); 4=Four,
Collections_ut System.out.print(sm2); 6=Six,
il_NewQB }} MCQ 7=Seven}
Collections_ut next() method of Scanner class will return
il_NewQB _________ MCQ Integer
Given:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class MainClass {

public static void main(String[] a) {


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

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


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

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

A)Property files help to decrease coupling


B) DateFormat class allows you to format dates
and times with customized styles.
C) Calendar class allows to perform date
calculation and conversion of dates and times
Collections_ut between timezones. A and B is
il_NewQB D) Vector class is not synchronized MCQ TRUE
Collections_ut Which interface does java.util.Hashtable
il_NewQB implement? MCQ Java.util.Map

Collections_ut Object get(Object key) - What does this method


il_NewQB return if the key is not found in the Map? MCQ

Consider the following code and choose the


correct option:
class Test{
public static void main(String args[]){
TreeSet<Integer> ts=new TreeSet<Integer>();
ts.add(1);
ts.add(8);
ts.add(6);
ts.add(4);
SortedSet<Integer> ss=ts.subSet(2, 10);
ss.add(9);
System.out.println(ts);
Collections_ut System.out.println(ss); [1,4,6,8]
il_NewQB }} MCQ [4,6,8,9]
A) Iterator does not allow to insert elements
during traversal
B) Iterator allows bidirectional navigation.
C) ListIterator allows insertion of elements
during traversal
Collections_ut D) ListIterator does not support bidirectional A and B is
il_NewQB navigation MCQ TRUE
Collections_ut static void sort(List list) method is part of Collection
il_NewQB ________ MCQ interface
Collections_ut static int binarySearch(List list, Object key) is a
il_NewQB method of __________ MCQ Vector class

Which collection class allows you to access its


Collections_ut elements by associating a key with an java.util.Sorte
il_NewQB element's value, and provides synchronization? MCQ dMap

Consider the following code and select the


correct output:
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class Lists {
public static void main(String[] args) {
List<String> list=new ArrayList<String>();
list.add("1");
list.add("2");
list.add(1, "3");
List<String> list2=new LinkedList<String>(list);
list.addAll(list2);
list2 =list.subList(2,5);
list2.clear();
System.out.println(list);
Collections_ut }
il_NewQB } MCQ [1,3,2]
Given:
import java.util.*;

public class LetterASort{


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

A) It is a good practice to store heterogenous


data in a TreeSet.
B) HashSet has default initial capacity (16) and
loadfactor(0.75)
C)HashSet does not maintain order of
Collections_ut Insertion A and B is
il_NewQB D)TreeSet maintains order of Inserstion MCQ TRUE

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


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

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


s.add("g");
s.pollFirst();
s.pollFirst();
Collections_ut s.add("c2"); The size of s
il_NewQB System.out.println(s.size() +" "+ subs.size()); MCA is 4

Consider the following code was executed on


June 01, 1983. What will be the output?
class Test{
public static void main(String args[]){
Date date=new Date();
SimpleDateFormat sd;
sd=new SimplpeDateFormat("E MMM dd
Collections_ut yyyy"); Wed Jun 01
il_NewQB System.out.print(sd.format(date));}} MCQ 1983
Given:
public class Venus {
public static void main(String[] args) {
int [] x = {1,2,3};
int y[] = {4,5,6};
new Venus().go(x,y);
}
void go(int[]... z) {
for(int[] a : z)
System.out.print(a[0]);
Collections_ut }
il_NewQB } What is the result? MCQ 123

You wish to store a small amount of data and


make it available for rapid access. You do not
have a need for the data to be sorted,
uniqueness is not an issue and the data will
remain fairly static Which data structure might
be most suitable for this requirement?

1) TreeSet
2) HashMap
Collections_ut 3) LinkedList
il_NewQB 4) an array MCQ 1

What will be the output of following code?


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

Consider the code below & select the correct


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

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

Consider the following code and choose the


correct output:
Control class Test{
structures public static void main(String args[]){
wrapper boolean flag=true;
classes auto if(flag=false){
boxing System.out.print("TRUE");}else{
NewQB System.out.print("FALSE");}}} MCQ true
Cosider the following code and choose the
Control correct option:
structures class Test{
wrapper public static void main(String args[])
classes auto { System.out.println(Integer.parseInt("214748
boxing 3648", 10)); Compilation
NewQB }} MCQ error

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

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

Control
structures
wrapper
classes auto What is the range of the random number r
boxing generated by the code below?
NewQB int r = (int)(Math.floor(Math.random() * 8)) + 2; MCQ 2 <= r <= 9
class Test{
public static void main(String[] args) {
int x=-1,y=-1;
if(++x=++y)
System.out.println("R.T. Ponting");
Control else
structures System.out.println("C.H. Gayle");
wrapper }
classes auto }
boxing consider the code above & select the proper
NewQB output from the options. MCQ R.T.Ponting

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

Consider the following code and choose the


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

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

What is the value of ’n’ after executing the


following code?
int n = 10;
int p = n + 5;
int q = p - 10;
int r = 2 * (p - q);
switch(n)
Control {
structures case p: n = n + 1;
wrapper case q: n = n + 2;
classes auto case r: n = n + 3;
boxing default: n = n + 4;
NewQB } MCQ 14
public class While
{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x +
Control 1)); /* Line 8 */
structures }
wrapper }
classes auto } There is a
boxing syntax error
NewQB Which statement is true? MCQ on line 1

Which of the following loop bodies DOES


compute the product from 1 to 10 like (1 * 2 * 3
*4*5*
Control 6 * 7 * 8 * 9 * 10)?
structures int s = 1;
wrapper for (int i = 1; i <= 10; i++)
classes auto {
boxing <What to put here?>
NewQB } MCQ s += i * i;

Control
structures
wrapper
classes auto
boxing Which of the following statements are true String is a
NewQB regarding wrapper classes? (Choose TWO) MCA wrapper class

Given:
class Atom {
Atom() { System.out.print("atom "); }
}
class Rock extends Atom {
Rock(String type) { System.out.print(type); }
}
public class Mountain extends Rock {
Mountain() {
super("granite ");
Control new Rock("granite ");
structures }
wrapper public static void main(String[] a) { new
classes auto Mountain(); }
boxing } Compilation
NewQB What is the result? MCQ fails.
What are the thing to be placed to complete the
code?
class Wrap {
public static void main(String args[]) {

_______________ iOb = ___________


Integer(100);

Control int i = iOb.intValue();


structures
wrapper System.out.println(i + " " + iOb); // displays
classes auto 100 100
boxing }
NewQB } MCQ int, int

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)
{
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
Control default: j++;
structures }
wrapper return j + x;
classes auto }
boxing }
NewQB What will be the output of the program? MCQ value = 8

Given:
public class Barn {
public static void main(String[] args) {
new Barn().go("hi", 1);
new Barn().go("hi", "world", 2);
Control }
structures public void go(String... y, int x) {
wrapper System.out.print(y[y.length - 1] + " ");
classes auto }
boxing }
NewQB What is the result? MCQ hi hi
Consider the following code and choose the
correct option:
class Test{
Control public static void main(String args[]){ int
structures x=034;
wrapper int y=12;
classes auto int ans=x+y;
boxing System.out.println(ans);
NewQB }} MCQ 40

11. double input = 314159.26;


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

Consider the following code and choose the


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

Control Consider the following code and choose the


structures correct option:
wrapper class Test{
classes auto public static void main(String args[]){
boxing Long data=23;
NewQB System.out.println(data); }} MCQ 23

class AutoBox {
public static void main(String args[]) {

int i = 10;
Control Integer iOb = 100;
structures i = iOb;
wrapper System.out.println(i + " " + iOb);
classes auto } No,
boxing } whether this code work properly, if so what Compilation
NewQB would be the result? MCQ error
Control Consider the following code and choose the
structures correct option:
wrapper class Test{
classes auto public static void main(String args[]){
boxing Long l=0l; Compilation
NewQB System.out.println(l.equals(0));}} MCQ error

int I = 0;
outer:
while (true)
{
I++;
inner:
for (int j = 0; j < 10; j++)
{
I += j;
if (j == 3)
continue inner;
break outer;
Control }
structures continue outer;
wrapper }
classes auto System.out.println(I);
boxing
NewQB What will be thr result? MCQ 3

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;
Control if(i==10) The code will
structures if(i<10) fail to compile
wrapper System.out.println("a"); because the
classes auto else syntax of the if
boxing System.out.println("b"); statement is
NewQB }} MCQ incorrect

What is the output of the following code :


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

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

What will be the output of following code?

TreeSet map = new TreeSet();


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

public class Test {


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

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


System.out.print("1 ");
Control System.out.print("2 ");
structures if ((b2 = true) && b1 )
wrapper System.out.print("3 ");
classes auto }
boxing }
NewQB What is the result? MCQ 2
Control
structures
wrapper
classes auto HashTable is
boxing a sub class of
NewQB Which of these statements are true? MCA Dictionary

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

What is the output :


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

Consider the following code and choose the


correct output:
class Test{
public static void main(String args[]){
int num='b'; switch(num){
Control default :{
structures System.out.print("default");}
wrapper case 100 : case 'b' : case 'c' : {
classes auto System.out.println("brownie"); break;}
boxing case 200: case 'e': {
NewQB System.out.println("pastry"); }break; } }} MCQ brownie
Given:
int a = 5;
int b = 5;
int c = 5;
if (a > 3)
if (b > 4)
if (c > 5)
c += 1;
else
Control c += 2;
structures else
wrapper c += 3;
classes auto c += 4;
boxing What is the value of variable c after executing
NewQB the following code? MCQ 3

Given:
Float pi = new Float(3.14f);
if (pi > 3) {
System.out.print("pi is bigger than 3. ");
}
else {
Control System.out.print("pi is not bigger than 3. ");
structures }
wrapper finally {
classes auto System.out.println("Have a nice day.");
boxing } Compilation
NewQB What is the result? MCQ fails.

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

int count = 1;
while ( ___________ )
{
System.out.print( count + " " );
count = count + 1;
}
Control System.out.println( );
structures
wrapper What condition should be used so that the code
classes auto prints:
boxing
NewQB 12345678 MCQ count < 9

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++)
{
switch (z)
{
case y: System.out.print("0 "); /*
Line 11 */
case x-1: System.out.print("1 "); /*
Line 12 */
Control case x: System.out.print("2 "); /*
structures Line 13 */
wrapper }
classes auto }
boxing }
NewQB } MCQ 012

Given:
int x = 0;
int y = 10;
Control do {
structures y--;
wrapper ++x;
classes auto } while (x < 5);
boxing System.out.print(x + "," + y);
NewQB What is the result? MCQ 5,6
What is the output :
class Test{
public static void main(String[] args) {
int a=5,b=10,c=1;
if(a>c){
System.out.println("success");
Control }
structures else{
wrapper break;
classes auto }
boxing }
NewQB } MCQ success

Consider the following code and choose the


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

Consider the following code and choose the


Control correct option:
structures class Test{
wrapper public static void main(String args[]){
classes auto int l=7;
boxing Long L = (Long)l;
NewQB System.out.println(L); }} MCQ 7

Given:
double height = 5.5;
if(height-- >= 5.0)
System.out.print("tall ");
if(--height >= 4.0)
System.out.print("average ");
Control if(height-- >= 3.0)
structures System.out.print("short ");
wrapper else
classes auto System.out.print("very short ");
boxing }
NewQB What would be the Result? MCQ tall
Consider the following code and choose the
Control correct option:
structures class Test{
wrapper public static void main(String args[]){
classes auto String hexa = "0XFF";
boxing int number = Integer.decode(hexa); Compilation
NewQB System.out.println(number); }} MCQ error

Consider the following code and choose the


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

Control
structures
wrapper
classes auto Person[] p =
boxing Which of the following statements about arrays new
NewQB is syntactically wrong? MCQ Person[5];

What will be the output of following code?

import java.util.*;
class I
{
public static void main (String[] args)
{
Control Object i = new ArrayList().iterator();
structures System.out.print((i instanceof List)+",");
wrapper System.out.print((i instanceof Iterator)+",");
classes auto System.out.print(i instanceof ListIterator);
boxing } Prints: false,
NewQB } MCQ false, false
Given:
public static void test(String str) {
int check = 4;
if (check = str.length()) {
System.out.print(str.charAt(check -= 1) +", ");
} else {
System.out.print(str.charAt(0) + ", ");
}
Control }
structures and the invocation:
wrapper test("four");
classes auto test("tee");
boxing test("to");
NewQB What is the result? MCQ r, t, t,

What will be the output of the program?


Control int x = 3;
structures int y = 1;
wrapper if (x = y) /* Line 3 */
classes auto {
boxing System.out.println("x =" + x);
NewQB } MCQ x=1

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");
tSet.add("2");
tSet.add("3");
tSet.add("4");
tSet.add("5");
Control SortedSet sortedSet =_____________("3");
structures System.out.println("Head Set Contains : " +
wrapper sortedSet);
classes auto }
boxing } What is the missing method in the code to get
NewQB the head set of the tree set? MCQ tSet.headSet
Consider the following code and choose the
correct output:
class Test{
public static void main(String args[]){
int num=3; switch(num){
Control default :{
structures System.out.print("default");}
wrapper case 1: case 3: case 4: {
classes auto System.out.println("apple"); break;}
boxing case 2: case 5: {
NewQB System.out.println("black berry"); }break; } }} MCQ apple

Consider the following code and choose the


correct option:
Control class Test{
structures public static void main(String args[]){
wrapper Long L = null; long l = L;
classes auto System.out.println(L);
boxing System.out.println(l);
NewQB }} MCQ null 0

What does the following code fragment write to


the monitor?

int sum = 21;


if ( sum != 20 )
System.out.print("You win ");
Control else
structures System.out.print("You lose ");
wrapper
classes auto System.out.println("the prize.");
boxing You win the
NewQB What does the code fragment prints? MCQ prize

Control
structures
wrapper The return
classes auto type of the
boxing Which statements are true about maps? values()
NewQB (Choose TWO) MCA method is set

Control
structures
wrapper Which collection implementation is suitable for
classes auto maintaining an ordered sequence of
boxing objects,when objects are frequently inserted in
NewQB and removed from the middle of the sequence? MCQ TreeMap
OutputStream
is the abstract
Control superclass of
structures all classes
wrapper that represent
classes auto an
boxing outputstream
NewQB Choose TWO correct options: MCA of bytes.

What is the output :


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

A continue
Control statement
structures doesn’t
wrapper transfer
classes auto control to the
boxing Which of the following statements is TRUE test statement
NewQB regarding a Java loop? MCQ of the for loop

switch(x)
{
default:
System.out.println("Hello");
}
Which of the following are acceptable types for
x?
Control 1.byte
structures 2.long
wrapper 3.char
classes auto 4.float
boxing 5.Short
NewQB 6.Long MCQ 1 ,3 and 5
Used to
release the
resources
Exception_ha which are
ndling_NewQ Which are true with respect to finally block? obtained in try
B (Choose THREE) MCA block.

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();
}
public void start(){ A compile
for (int i = 0; i <10; i++){ time error
System.out.println("Value of i = " indicating that
+ i); no run method
Exception_ha } is defined for
ndling_NewQ } the Thread
B } MCQ class

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

Deadlock will
Exception_ha not occur if
ndling_NewQ Which of the following statements are true? wait()/notify()
B (Choose TWO) MCA is used
public class MyProgram
{
public static void throwit()
{
throw new RuntimeException();
}
public static void main(String args[])
{
try
{
System.out.println("Hello world ");
throwit();
System.out.println("Done with try block
");
}
finally
{
System.out.println("Finally executing ");
}
}
Exception_ha } The program
ndling_NewQ which answer most closely indicates the will not
B behavior of the program? MCQ compile.
If a method is capable of causing an exception
that it does not handle, it must specify this
Exception_ha behavior using throws so that callers of the
ndling_NewQ method can guard themselves against such
B Exception MCQ false

A) Checked Exception must be explicity caught


or propagated to the calling method
B) If runtime system can not find an appropriate
Exception_ha method to handle the exception, then the
ndling_NewQ runtime system terminates and uses the default Only A is
B exception handler. MCQ TRUE
public class RTExcept
{
public static void throwit ()
{
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args)
{
try
{
System.out.print("hello ");
throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
}
Exception_ha System.out.println("after "); hello throwit
ndling_NewQ } caught finally
B } MCQ after

class s implements Runnable


{
int x, y;
public void run()
{
for(int i = 0; i < 1000; i++)
synchronized(this)
{
x = 12;
y = 12;
}
System.out.print(x + " " + y + " ");
}
public static void main(String args[])
{
s run = new s();
Thread t1 = new Thread(run);
Thread t2 = new Thread(run);
t1.start();
Exception_ha t2.start();
ndling_NewQ }
B } What is the output? MCQ DeadLock
What is wrong with the following code?

Class MyException extends Exception{}


public class Test{
public void foo() {
try {
bar(); Since the
} finally { method foo()
baz(); does not
} catch(MyException e) {} catch the
} exception
public void bar() throws MyException { generated by
throw new MyException(); the method
} baz(),it must
public void baz() throws RuntimeException { declare the
Exception_ha throw new RuntimeException(); RuntimeExce
ndling_NewQ } ption in a
B } MCQ throws clause

Consider the following code and choose the


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

If an
exception is
not caught in
a method,the
method will
terminate and
Exception_ha normal
ndling_NewQ execution will
B Choose TWO correct options: MCA resume
Which four can be thrown using the throw
statement?

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

class X implements Runnable


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

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

public class SubB extends X {


public void foo() throws RuntimeException {
super.foo();
if (true) throw new RuntimeException();
System.out.print("B ");
}
public static void main(String[] args) {
new SubB().foo();
Exception_ha }
ndling_NewQ } X, followed by
B What is the result? MCQ an Exception.
What will the output of following code?

try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
Exception_ha System.out.println(" Arithmetic Exception");
ndling_NewQ }
B System.out.println("finished"); MCQ finished
Exception_ha
ndling_NewQ
B Which of the following methods are static? MCA start()

static methods
are difficult to
maintain,
because you
can not
Exception_ha change their
ndling_NewQ Which of the following statements regarding implementatio
B static methods are correct? (2 answers) MCA n.

Consider the following code and choose the


correct option:
class Test{
static void display(){
throw new RuntimeException();
} public static void main(String args[]){
try{display();
}catch(Exception e){ throw new
NullPointerException();}
finally{try{ display();
Exception_ha }catch(NullPointerException e)
ndling_NewQ { System.out.println("caught");}
B finally{ System.out.println("exit");}}}} MCQ caught exit
class Test{
public static void main(String[] args){
try{
Integer.parseInt("1.0");
}
catch(Exception e){
System.out.println("Exception occurred");
}
catch(RuntimeException ex){
System.out.println("RuntimeException");
}
Exception_ha }}
ndling_NewQ consider the code above & select the proper Exception
B output from the options. MCQ occurred

Which three of the following are methods of the


Object class?

1.notify();
2.notifyAll();
3.isInterrupted();
4.synchronized();
5.interrupt();
Exception_ha 6.wait(long msecs);
ndling_NewQ 7.sleep(long msecs);
B 8.yield(); MCQ 1, 2, 4

In the given code snippet


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

class Trial{
public static void main(String[] args){
try{
System.out.println("One");
int y = 2 / 0;
System.out.println("Two");
}
catch(RuntimeException ex){
System.out.println("Catch");
}
finally{
Exception_ha System.out.println("Finally");
ndling_NewQ } One Two
B }} MCQ Catch Finally
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");
}
catch(RuntimeException e) {
System.out.println("2");
return;
}
catch(Exception e) {
System.out.println("3");
}
finally{
System.out.println("4");
}
Exception_ha System.out.println("5"); The program
ndling_NewQ } will only print
B } MCQ 5

class Trial{
public static void main(String[] args){
Exception_ha try{
ndling_NewQ System.out.println("Java is portable"); Java is
B }}} MCQ portable

class Animal { public String noise() { return


"peep"; } }
class Dog extends Animal {
public String noise() { return "bark"; }
}
class Cat extends Animal {
public String noise() { return "meow"; }
}
class try1{
public static void main(String[] args){
Animal animal = new Dog();
Cat cat = (Cat)animal;
System.out.println(cat.noise());
Exception_ha }}
ndling_NewQ consider the code above & select the proper
B output from the options. MCQ bark
Given:
class X implements Runnable
{
public static void main(String args[])
{
/* Some code */
} X run = new
public void run() {} X(); Thread t =
Exception_ha } new
ndling_NewQ Which of the following line of code is suitable to Thread(run);
B start a thread ? MCQ t.start();

A static
Exception_ha method
ndling_NewQ cannot be
B Which statement is true? MCQ synchronized.

Consider the following code and choose the


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

Given:
public class ExceptionTest
{
class TestException extends Exception {}
public void runTest() throws TestException {}
public void test() /* Line X */
{
runTest();
}
Exception_ha }
ndling_NewQ At Line X, which code is necessary to make the No code is
B code compile? MCQ necessary
Implement
java.lang.Run
Exception_ha nable and
ndling_NewQ Which two can be used to create a new implement the
B Thread? MCA run() method.

A try
statement
must have at
Exception_ha least one
ndling_NewQ corresponding
B Choose the correct option: MCQ catch block

class PropagateException{
public static void main(String[] args){
try{
method();
System.out.println("method() called");
}
catch(ArithmeticException ex){
System.out.println("Arithmetic Exception");
}
catch(RuntimeException re){
System.out.println("Runtime Exception");
}}
static void method(){
int y = 2 / 0;
Exception_ha }}
ndling_NewQ consider the code above & select the proper Arithmetic
B output from the options. MCQ Exception

Given:
static void test() {
try {
String x = null;
System.out.print(x.toString() + " ");
}
finally { System.out.print("finally "); }
}
public static void main(String[] args) {
try { test(); }
catch (Exception ex)
Exception_ha { System.out.print("exception "); }
ndling_NewQ }
B What is the result? MCQ null
Given two programs:
1. package pkgA;
2. public class Abc {
3. int a = 5;
4. protected int b = 6;
5. public int c = 7;
6. }

3. package pkgB;
4. import pkgA.*;
5. public class Def {
6. public static void main(String[] args) {
7. Abc f = new Abc();
8. System.out.print(" " + f.a);
9. System.out.print(" " + f.b);
10. System.out.print(" " + f.c);
11. }
Exception_ha 12. }
ndling_NewQ What is the result when the second program is
B run? (Choose all that apply) MCA 567

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)
{
System.out.print("End of file exception");
}
catch(FileNotFoundException e)
{
System.out.print("File not found");
}

given that EOFException and


Exception_ha FileNotFoundException are both subclasses of
ndling_NewQ IOException. If this block of code is pasted in a The code will
B method, choose the best option. MCQ not compile.

catch(X x) can
catch
subclasses of
Exception_ha X where X is a
ndling_NewQ subclass of
B Which of the following statements is true? MCQ Exception.
Consider the following code and choose the
Exception_ha correct option:
ndling_NewQ int array[] = new int[10]; compiles
B array[-1] = 0; MCQ successfully

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
{
System.out.print("hello ");
throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
}
Exception_ha System.out.println("after ");
ndling_NewQ } hello throwit
B } MCQ caught
Exception_ha What is the keyword to use when the access of
ndling_NewQ a method has to be restricted to only one
B thread at a time MCQ volatile

Consider the following code and choose the


correct option:
class Test{
public static void parse(String str) {
try { int num = Integer.parseInt(str);
} catch (NumberFormatException nfe) {
Exception_ha num = 0; } finally { System.out.println(num);
ndling_NewQ } } public static void main(String[] args) {
B parse("one"); } MCQ
public static void parse(String str) {
try {
float f = Float.parseFloat(str);
} catch (NumberFormatException nfe) {
f = 0;
} finally {
System.out.println(f);
}
}
Exception_ha public static void main(String[] args) {
ndling_NewQ parse("invalid");
B } MCQ

Given the following program,which statements


are true? (Choose TWO)
Public class Exception {
public static void main(String[] args) {
try {
if(args.length == 0) return; If run with no
System.out.println(args[0]); arguments,the
Exception_ha }finally { program will
ndling_NewQ System.out.println("The end"); produce no
B }}} MCA output
Which can appropriately be thrown by a
Exception_ha programmer using Java SE technology to
ndling_NewQ create ClassCastExc
B a desktop application? MCQ eption
Exception_ha
ndling_NewQ Arithmetic
B Which of the following is a checked exception? MCQ Exception

Given:
11. class A {
12. public void process()
{ System.out.print("A,"); }
13. class B extends A {
14. public void process() throws IOException {
15. super.process();
16. System.out.print("B,");
17. throw new IOException();
18. }
19. public static void main(String[] args) {
20. try { new B().process(); }
21. catch (IOException e)
Exception_ha { System.out.println("Exception"); }
ndling_NewQ 22. }
B What is the result? MCQ Exception
The notifyAll()
method must
be called from
Exception_ha a
ndling_NewQ synchronized
B Which statement is true? MCQ context

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

consider the code & choose the correct output:


class Threads2 implements Runnable {

public void run() {


System.out.println("run.");
throw new RuntimeException("Problem");
}
public static void main(String[] args) {
Thread t = new Thread(new Threads2());
t.start();
Exception_ha System.out.println("End of method."); java.lang.Runt
ndling_NewQ } imeException:
B } MCQ Problem
Exception_ha
ndling_NewQ The exceptions for which the compiler doesn’t Checked
B enforce the handle or declare rule MCQ exceptions

Consider the code below & select the correct


ouput from the options:
public class Test{
Integer i;
int x;
Test(int y){
x=i+y;
System.out.println(x);
}
Exception_ha public static void main(String[] args) {
ndling_NewQ new Test(new Integer(5));
B }} MCQ 5
Given:
public class TestSeven extends Thread {
private static int x;
public synchronized void doThings() {
int current = x;
current++;
x = current;
}
public void run() {
doThings();
Exception_ha }
ndling_NewQ } Compilation
B Which statement is true? MCQ fails.

Consider the following code and choose the


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

An object is
deleted as
soon as there
are no more
Garbage_Coll Which statements describe guaranteed references
ection_NewQ behaviour of the garbage collection and that denote
B finalization mechanisms? (Choose TWO) MCA the object

Which statement is true?


A. A class's finalize() method CANNOT be
invoked explicitly.
B. super.finalize() is called implicitly by any
overriding finalize() method.
C. The finalize() method for a given object is
called no more than once by the garbage
collector.
Garbage_Coll D. The order in which finalize() is called on two
ection_NewQ objects is based on the order in which the two
B objects became finalizable. MCQ A
Garbage_Coll
ection_NewQ Which of the following allows a programmer to
B destroy an object x? MCQ x.delete()

class X2
{
public X2 x;
public static void main(String [] args)
{
X2 x2 = new X2(); /* Line 6 */
X2 x3 = new X2(); /* Line 7 */
x2.x = x3;
x3.x = x2;
x2 = new X2();
x3 = x2; /* Line 11 */
}
}
Garbage_Coll
ection_NewQ after line 11 runs, how many objects are eligible
B for garbage collection? MCQ

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

public static String removeChar(String s,


char c) {
String r = "";
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != c)
r += s.charAt(i);
}
Garbage_Coll return r;
ection_NewQ }
B } What would be the result? MCQ This is java

Set all
references to
the object to
Garbage_Coll new
ection_NewQ How can you force garbage collection of an values(null,
B object? MCQ for example).
Consider the following code and choose the
correct option:
public class X
{
public static void main(String [] args)
{
X x = new X();
X x2 = m1(x); /* Line 6 */
X x4 = new X();
x2 = x4; /* Line 8 */
doComplexStuff(); }
static X m1(X mx) {
mx = new X();
Garbage_Coll return mx; }}
ection_NewQ After line 8 runs. how many objects are eligible
B for garbage collection? MCQ

interface interface_1 {
void f1();
}
class Class_1 implements interface_1 {
void f1() {
System.out.println("From F1 funtion in
Class_1 Class");
}
}
public class Demo1 {
Inheritance_In public static void main(String args[]) {
terfaces_Abstr Class_1 o11 = new Class_1();
act o11.f1(); From F1
Classes_New } function in
QB } MCQ Class_1 Class
Given:
class A {
final void meth() {
System.out.println("This is a final method.");
}
}
class B extends A {
void meth() {
System.out.println("Illegal!");
}
}
class MyClass8{
public static void main(String[] args) {
A a = new A();
Inheritance_In a.meth();
terfaces_Abstr B b= new B();
act b.meth();
Classes_New } This is a final
QB }What would be the result? MCQ method illegal

Which Man class properly represents the


relationship "Man has a best friend who is a
Inheritance_In Dog"?
terfaces_Abstr A)class Man extends Dog { }
act B)class Man implements Dog { }
Classes_New C)class Man { private BestFriend dog; }
QB D)class Man { private Dog bestFriend; } MCQ A
What will be the output of the program?

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

public class SubClass extends SuperClass


{
public Long getLength()
{
return new Long(5);
}

public static void main(String[] args)


{
SuperClass sp = new SuperClass();
SubClass sb = new SubClass();
Inheritance_In System.out.println(
terfaces_Abstr sp.getLength().toString() + "," +
act sub.getLength().toString() );
Classes_New }
QB } MCQ 4, 4

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{
public static void main(String[] args) {
Inheritance_In Cd cd=new Cd();
terfaces_Abstr Bc bc=new Cd();
act Ab ab=new Cd();
Classes_New System.out.println(cd.getN()+" "+
QB bc.getN()+" "+ab.getN()); }} MCQ 000
interface A{}
class B implements A{}
class C extends B{}
public class Test extends C{
public static void main(String[] args) {
Inheritance_In C c=new C();
terfaces_Abstr /* Line6 */}}
act
Classes_New Which code, inserted at line 6, will cause a
QB java.lang.ClassCastException? MCQ B b=c;

Given :
What would be the result of compiling and
running the following program?
// Filename: MyClass.java
public class MyClass {
public static void main(String[] args) {
C c = new C();
System.out.println(c.max(13, 29));
}
}
class A {
int max(int x, int y) { if (x>y) return x; else return
y; } The code will
} fail to compile
class B extends A{ because the
int max(int x, int y) { return super.max(y, x) - 10; max() method
} in B passes
Inheritance_In } the arguments
terfaces_Abstr class C extends B { in the call
act int max(int x, int y) { return super.max(x+10, super.max(y,
Classes_New y+10); } x) in the
QB } MCQ wrong order.

The concept of multiple inheritance is


implemented in Java by

Inheritance_In (A) extending two or more classes


terfaces_Abstr (B) extending one class and implementing one
act or more interfaces
Classes_New (C) implementing two or more interfaces
QB (D) all of these MCQ (A)
Given:
interface DoMath
{
double getArea(int r);
}
interface MathPlus class AllMath
Inheritance_In { extends
terfaces_Abstr double getVolume(int b, int h); DoMath
act } { double
Classes_New /* Missing Statements ? */ getArea(int
QB Select the correct missing statements. MCQ r); }

Consider the following code and choose the


correct option:
class A{
void display(byte a, byte b){
Inheritance_In System.out.println("sum of byte"+(a+b)); }
terfaces_Abstr void display(int a, int b){
act System.out.println("sum of int"+(a+b)); }
Classes_New public static void main(String[] args) {
QB new A().display(3, 4); }} MCQ sum of byte 7

Consider the following code and choose the


correct option:
interface Output{
void display();
void show();
Inheritance_In }
terfaces_Abstr class Screen implements Output{
act void display(){ System.out.println("display"); }
Classes_New public static void main(String[] args) {
QB new Screen().display();}} MCQ display

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");
}
}
class CastTest2 {
public static void main(String [] args) {
Dog a = (Dog) new Animal();
Inheritance_In a.makeNoise();
terfaces_Abstr }
act }
Classes_New consider the code above & select the proper
QB output from the options. MCQ run time error
Consider the following code and choose the
correct option:
interface employee{
void saldetails();
void perdetails();
}
abstract class perEmp implements employee{
public void perdetails(){
System.out.println("per details"); }}
class Programmer extends perEmp{
public void saldetails(){
Inheritance_In perdetails();
terfaces_Abstr System.out.println("sal details"); }
act public static void main(String[] args) {
Classes_New perEmp emp=new Programmer();
QB emp.saldetails(); }} MCQ sal details

Consider the code below & select the correct


ouput from the options:
class A{
static int sq(int n){
return n*n; }}
Inheritance_In public class Test extends A{
terfaces_Abstr static int sq(int n){
act return super.sq(n); }
Classes_New public static void main(String[] args) {
QB System.out.println(new Test().sq(3)); }} MCQ 3

Inheritance_In Given: No—a


terfaces_Abstr public static void main( String[] args ) variable must
act { SomeInterface x; ... } always be an
Classes_New Can an interface name be used as the type of a object
QB variable MCQ reference type

Consider the following code and choose the


correct option:
interface A{
int i=3;}
interface B{
int i=4;}
Inheritance_In class Test implements A,B{
terfaces_Abstr public static void main(String[] args) {
act System.out.println(i);
Classes_New }
QB } MCQ 3
Given the following classes and declarations,
which statements are true?
// Classes
class A {
private int i;
public void f() { /* ... */ }
public void g() { /* ... */ }
}
class B extends A{
public int j;
public void g() { /* ... */ }
Inheritance_In }
terfaces_Abstr // Declarations:
act A a = new A(); The B class is
Classes_New B b = new B(); a subclass of
QB Select the three correct answers. MCA A.

Which declaration can be inserted at (1) without


causing a compilation error?
Inheritance_In interface MyConstants {
terfaces_Abstr int r = 42;
act int s = 69;
Classes_New // (1) INSERT CODE HERE int total = total
QB } MCA + r + s;

What is the output for the following code:


abstract class One{
private abstract void test();
}
class Two extends One{
void test(){
System.out.println("hello");
}}
class Test{
Inheritance_In public static void main(String[] args){
terfaces_Abstr Two obj = new Two();
act obj.test();
Classes_New } run time
QB } MCQ exception

Consider the code below & select the correct


ouput from the options:

class Money {
private String country = "Canada";
Inheritance_In public String getC() { return country; } }
terfaces_Abstr class Yen extends Money {
act public String getC() { return super.country; }
Classes_New public static void main(String[] args) {
QB System.out.print(new Yen().getC() ); } } MCQ Canada
we must use
always
Inheritance_In extends and
terfaces_Abstr later we must
act When we use both implements & extends use
Classes_New keywords in a single java program then what is implements
QB the order of keywords to follow? MCQ keyword.

Consider the code below & select the correct


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

Given:
interface DeclareStuff {
public static final int Easy = 3;
void doStuff(int t); }
public class TestDeclare implements
DeclareStuff {
public static void main(String [] args) {
int x = 5;
new TestDeclare().doStuff(++x);
}
Inheritance_In void doStuff(int s) {
terfaces_Abstr s += Easy + ++s;
act System.out.println("s " + s);
Classes_New }
QB } What is the result? MCQ s 14
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
}
class E extends D implements C { //Line 7
Inheritance_In public void methodA() { }
terfaces_Abstr public void methodB() { } //Line 9 Compilation
act public void methodC() { } fails, due to
Classes_New } an error in line
QB What would be the result? MCQ 3

Inheritance_In
terfaces_Abstr It can only be
act used in the
Classes_New Which of the following statements is true parent's
QB regarding the super() method? MCQ constructor

Consider the following code and choose the


correct option:
interface Output{
void display();
void show();
}
Inheritance_In class Screen implements Output{
terfaces_Abstr void show() {System.out.println("show");}
act void display(){ System.out.println("display"); }
Classes_New public static void main(String[] args) {
QB new Screen().display();}} MCQ display

Consider the following code and choose the


correct option:
class A{
void display(){ System.out.println("Hello A"); }}
class B extends A{
void display(){
Inheritance_In System.out.println("Hello B"); }}
terfaces_Abstr public class Test {
act public static void main(String[] args) {
Classes_New B b=(B) new A();
QB b.display(); }} MCQ Hello A
Consider the following code:
// Class declarations:
class Super {}
class Sub extends Super {}
Inheritance_In // Reference declarations:
terfaces_Abstr Super x;
act Sub y;
Classes_New Which of the following statements is correct for Illegal at
QB the code: y = (Sub) x? MCQ compile time

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

Consider the following code and choose the


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

Consider the following code and choose the


correct option:
class A{
void display(){ System.out.println("Hello A"); }}
class B extends A{
void display(){
System.out.println("Hello B"); }}
Inheritance_In public class Test {
terfaces_Abstr public static void main(String[] args) {
act A a=new B();
Classes_New B b= (B)a;
QB b.display(); }} MCQ Hello A
Because of
Inheritance_In single
terfaces_Abstr inheritance,
act Mammal can
Classes_New A class Animal has a subclass Mammal. Which have no
QB of the following is true: MCQ subclasses

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");
}
}
class CastTest2 {
public static void main(String [] args) {
Animal a = new Dog();
Inheritance_In a.makeNoise();
terfaces_Abstr }
act }
Classes_New consider the code above & select the proper
QB output from the options. MCQ run time error

What will be the result when you try to compile


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

public class Pri1 extends Base1 {


static int i = 200;

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


terfaces_Abstr Pri1 p = new Pri1();
act System.out.println(i);
Classes_New } Error at
QB } MCQ compile time
What is the output :
interface A{
void method1();
void method2();
}
class Test implements A{
public void method1(){
System.out.println("hello");}}
Inheritance_In class RunTest{
terfaces_Abstr public static void main(String[] args){
act Test obj = new Test();
Classes_New obj.method1();
QB }} MCQ hello

Given the following classes and declarations,


which statements are true?
// Classes
class Foo {
private int i;
public void f() { /* ... */ }
public void g() { /* ... */ }
}
class Bar extends Foo {
public int j;
Inheritance_In public void g() { /* ... */ }
terfaces_Abstr }
act // Declarations: The Bar class
Classes_New Foo a = new Foo(); is a subclass
QB Bar b = new Bar(); MCA of Foo.
Inheritance_In
terfaces_Abstr Given a derived class method which overrides
act one of it’s base class methods. With derived
Classes_New class object you can invoke the overridden super
QB base method using: MCQ keyword

Consider the following code and choose the


correct option:
abstract class Car{
abstract void accelerate();
}class Lamborghini extends Car{
@Override
void accelerate() {
System.out.println("90 mph");
Inheritance_In } void nitroBooster(){
terfaces_Abstr System.out.print("150 mph"); }
act public static void main(String[] args) {
Classes_New Car mycar=new Lamborghini(); Compilation
QB mycar.nitroBooster(); }} MCQ error
Given:
class Pizza {
java.util.ArrayList toppings;
public final void addTopping(String topping) {
toppings.add(topping);
}
}
public class PepperoniPizza extends Pizza {
public void addTopping(String topping) {
System.out.println("Cannot add Toppings");
}
public static void main(String[] args) {
Inheritance_In Pizza pizza = new PepperoniPizza();
terfaces_Abstr pizza.addTopping("Mushrooms");
act }
Classes_New } Compilation
QB What is the result? MCQ fails.

Consider the following code and choose the


correct option:
interface console{
int line=10;
void print();}
Inheritance_In class a implements console{
terfaces_Abstr void print(){
act System.out.print("A");}
Classes_New public static void main(String ar[]){
QB new a().print();}} MCQ A
Inheritance_In
terfaces_Abstr
act
Classes_New Which of these field declarations are legal in an public int
QB interface? (Choose all applicable) MCA answer = 42;

Given :
No—there
Day d; must always
Inheritance_In BirthDay bd = new BirthDay("Raj", 25); be an exact
terfaces_Abstr d = bd; // Line X match
act between the
Classes_New Where Birthday is a subclass of Day. State variable and
QB whether the code given at Line X is correct: MCQ the object
A super() or
this() call must
always be
provided
Inheritance_In explicitly as
terfaces_Abstr the first
act statement in
Classes_New the body of a
QB Select the correct statement: MCQ constructor.
Inheritance_In
terfaces_Abstr public final
act data type
Classes_New Choose the correct declaration of variable in an varaibale=intia
QB interface: MCQ lization;

Consider the following code and choose the


correct option:
abstract class Fun{
void time(){
System.out.println("Fun Time"); }}
class Run extends Fun{
Inheritance_In void time(){
terfaces_Abstr System.out.println("Fun Run"); }
act public static void main(String[] args) {
Classes_New Fun f1=new Run();
QB f1.time(); }} MCQ Fun Time

interface Vehicle{
void drive();
}
final class TwoWheeler implements Vehicle{
int wheels = 2;
public void drive(){
System.out.println("Bicycle");
}
}
class ThreeWheeler extends TwoWheeler{
public void drive(){
System.out.println("Auto");
}}
class Test{
public static void main(String[] args){
Inheritance_In ThreeWheeler obj = new ThreeWheeler();
terfaces_Abstr obj.drive();
act }}
Classes_New consider the code above & select the proper
QB output from the options. MCQ Auto
Consider the following code and choose the
correct option:
interface employee{
void saldetails();
void perdetails();
}
abstract class perEmp implements employee{
public void perdetails(){
Inheritance_In System.out.println("per details"); }}
terfaces_Abstr class Programmer extends perEmp{
act public static void main(String[] args) {
Classes_New perEmp emp=new Programmer();
QB emp.saldetails(); }} MCQ sal details
Inheritance_In
terfaces_Abstr
act
Classes_New abstract and
QB All data members in an interface are by default MCQ final

Consider the following code and choose the


correct option:
interface console{
int line;
void print();}
Inheritance_In class a implements console{
terfaces_Abstr public void print(){
act System.out.print("A");}
Classes_New public static void main(String ar[]){
QB new a().print();}} MCQ A

An abstract
class is one
Inheritance_In which
terfaces_Abstr contains
act general
Classes_New Which of the following is correct for an abstract purpose
QB class. (Choose TWO) MCA methods

Inheritance_In
terfaces_Abstr
act class Vehicle {
Classes_New Which of the following defines a legal abstract abstract void
QB class? MCQ display(); }
Consider the code below & select the correct
ouput from the options:

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

class Alps extends Mountain{


public Alps(int h){ super(h); }
Inheritance_In public Alps(){ this(100); }
terfaces_Abstr public static void main(String[] args) {
act System.out.println(new Alps().getH());
Classes_New }
QB } MCQ 100

Consider the given code and select the correct


output:

class SomeException {
}

class A {
public void doSomething() { }
}
Inheritance_In
terfaces_Abstr class B extends A {
act public void doSomething() throws Compilation of
Classes_New SomeException { } both classes A
QB } MCQ & B will fail

No—if a class
implements
several
Inheritance_In interfaces,
terfaces_Abstr each constant
act Is it possible if a class definition implements two must be
Classes_New interfaces, each of which has the same defined in only
QB definition for the constant? MCQ one interface
Inheritance_In Private
terfaces_Abstr methods
act cannot be
Classes_New overridden in
QB Select the correct statement: MCQ subclasses

Consider the following code and choose the


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

Introduction_t Which of the following option gives one To maintain


o_Java_and_ possible use of the statement 'the name of the the uniform
SDE_NewQB public class should match with its file name'? MCQ standard

Holds the
location of
Core Java
Introduction_t Class Library
o_Java_and_ Which of the following statement gives the use (Bootstrap
SDE_NewQB of CLASSPATH? MCQ classes)
Packages can
Introduction_t contain only
o_Java_and_ Which of the following are true about Java Source
SDE_NewQB packages? (Choose 2) MCA files
Introduction_t
o_Java_and_ Which of the following options give the valid
SDE_NewQB argument types for main() method? (Choose 2) MCA String [][]args
Introduction_t
o_Java_and_ Which of the following options give the valid dollorpack.
SDE_NewQB package names? (Choose 3) MCA $pack.$$pack

Introduction_t Object class is


o_Java_and_ Which of the following statements are true an abstract
SDE_NewQB regarding java.lang.Object class? (Choose 2) MCA class

Introduction_t
o_Java_and_ The term 'Java Platform' refers to Java Compiler
SDE_NewQB ________________. MCQ (Javac)

JDBC_NewQ Which of the following methods are needed for registerDriver(


B loading a database driver in JDBC? MCQ ) method

Using
forName()
JDBC_NewQ which is a
B how to register driver class in the memory? MCQ static method
Give Code snipet:
{// Somecode
ResultSet rs = st.executeQuery("SELECT *
FROM survey");

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

rs.close();
// somecode
JDBC_NewQ } What should be imported related to java.sql.Resul
B ResultSet? MCQ tSet

Consider the following code & select the correct


option for output.
String sql ="select empno,ename from emp";
PreparedStatement
pst=cn.prepareStatement(sql);
System.out.println(pst.toString());
ResultSet rs=pst.executeQuery(); will show first
JDBC_NewQ System.out.println(rs.getString(1)+ " employee
B "+rs.getString(2)); MCQ record
Which of the following methods finds the Connection.ge
JDBC_NewQ maximum number of connections that a specific tMaxConnecti
B driver can obtain? MCQ ons
JDBC_NewQ By default all JDBC transactions are
B autocommit. State TRUE/FALSE. MCQ true

JDBC_NewQ DriverManage
B getConnection() is method available in? MCQ r Class

A) By default, all JDBC transactions are auto


commit
B) PreparedStatement suitable for dynamic sql
and requires one time compilation
JDBC_NewQ C) with JDBC it is possible to fetch information Only A and B
B about the database MCQ is TRUE
There is no
such method
JDBC_NewQ What is the use of wasNull() in ResultSet in ResultSet
B interface? MCQ interface

Given :
public class MoreEndings {
public static void main(String[] args) throws
Exception {
Class driverClass =
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver
");
DriverManager.registerDriver((Driver)
driverClass.newInstance());
// Some code
JDBC_NewQ } Inorder to compile & execute this code, what
B should we import? MCQ java.sql.Driver
Which of the following method can be used to
JDBC_NewQ execute to execute all type of queries i.e. either
B Selection or Updation SQL Queries? MCQ executeAll()

JDBC_NewQ Which method will return boolean when we try executeUpdat


B to execute SQL Query from a JDBC program? MCQ e()

Cosider the following code & select the correct


output.
String sql ="select rollno, name from student";
PreparedStatement
pst=cn.prepareStatement(sql);
System.out.println(pst.toString());
ResultSet rs=pst.executeQuery();
JDBC_NewQ while(rs.next()){ will show only
B System.out.println(rs.getString(3)); } MCQ name

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


B by using ResultSet. State TRUE/FALSE MCQ true

JDBC_NewQ What is the default type of ResultSet in JDBC Read Only,


B applications? MCQ Forward Only
An application can connect to different
JDBC_NewQ Databases at the same time. State
B TRUE/FALSE. MCQ true
A) It is not possible to execute select query with
execute() method
JDBC_NewQ B) CallableStatement can executes store Both A and B
B procedures only but not functions MCQ is FALSE
A) When one use callablestatement, in that
case only parameters are send over network
not sql query.
JDBC_NewQ B) In preparestatement sql query will compile Both A and B
B for first time only MCQ is FALSE

Consider the code below & select the correct


ouput from the options:

String sql ="select * from ?";


String table=" txyz ";
PreparedStatement
pst=cn.prepareStatement(sql);
pst.setString(1,table );
ResultSet rs=pst.executeQuery(); will show all
JDBC_NewQ while(rs.next()){ row of first
B System.out.println(rs.getString(1)); } MCQ column
Sylvy wants to develop Student management
system, which requires frequent insert
operation about student details. In order to
JDBC_NewQ insert student record which statement interface
B will give good performance MCQ Statement

class CreateFile{
public static void main(String[] args) {
try {
File directory = new File("c"); //Line 13
File file = new File(directory,"myFile");
if(!file.exists()) {
file.createNewFile(); //Line 16
}}
catch(IOException e) {
e.printStackTrace }
}}}
If the current direcory does not consists of Line 16 is
JDBC_NewQ directory "c", Which statements are true ? never
B (Choose TWO) MCA executed
1) Driver 2)
Connection 3)
ResultSet 4)
JDBC_NewQ Which of the following options contains only DriverManage
B JDBC interfaces? MCQ r 5) Class

Consider the code below & select the correct


ouput from the options:

public class Test {


public static void main(String [] args) {
int x = 5;
boolean b1 = true;
boolean b2 = false;
if ((x == 4) && !b2 )
Keywords_var System.out.print("1 ");
iables_operat System.out.print("2 ");
ors_datatypes if ((b2 = true) && b1 )
_NewQB System.out.print("3 "); } MCQ 23
Keywords_var
iables_operat
ors_datatypes Which three are legal array declarations? int []
_NewQB (Choose THREE) MCA myScores [];

Consider the given code and select the correct


output:
class Test{
public static void main(String[] args){
Keywords_var int num1 = 012;
iables_operat int num2 = 0x110;
ors_datatypes int sum =num1+=num2;
_NewQB System.out.println("Ans = "+sum); }} MCQ 26
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;
Rat rat = new Rat();
Mouse mos = new Mouse();
Keywords_var PocketMouse pkt = new PocketMouse();
iables_operat
ors_datatypes Which one of the following will cause a compiler
_NewQB error? MCQ rod = mos

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){
try {
Keywords_var double d=Double.parseDouble(s);
iables_operat }catch(NumberFormatException nfe){
ors_datatypes d=0.0; }finally{
_NewQB System.out.println(d); } }} MCQ

Consider the code below & select the correct


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

public class Test extends A{


public int a=2;
public void add(){
this.a+=2; System.out.print("t"); }
Keywords_var public static void main(String[] args) {
iables_operat A a =new Test();
ors_datatypes a.add();
_NewQB System.out.print(a.a); }} MCQ t7
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++)
{
System.out.print(" " + argh[y]);
}
}
}
Keywords_var
iables_operat and the command-line invocation is
ors_datatypes
_NewQB > java CommandArgsTwo 1 2 3 MCQ 012

What will be the result of the following


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

Here is the general syntax for method


definition:

accessModifier returnType
methodName( parameterList )
{
Java statements

return returnValue; The


} returnValue
Keywords_var must be
iables_operat exactly the
ors_datatypes What is true for the returnType and the same type as
_NewQB returnValue? MCQ the returnType
Consider the following code and choose the
correct option:
class Test{
class A{ static int x=3; }
Keywords_var static void display(){
iables_operat System.out.println(A.x); }
ors_datatypes public static void main(String[] args) {
_NewQB display(); }} MCQ 3

Which of the following lines of code will compile


without warning or error?
1) float f=1.3;
Keywords_var 2) char c="a";
iables_operat 3) byte b=257;
ors_datatypes 4) boolean b=null;
_NewQB 5) int i=10; MCQ Line 3

Consider the following code and choose the


correct option:
class Test{
interface Y{
void display(); }
public static void main(String[] args) {
Keywords_var new Y(){
iables_operat public void display(){
ors_datatypes System.out.println("Hello World"); }
_NewQB }.display(); }} MCQ Hello World

Consider the following code and choose the


correct option:
class Test{
static class A{
interface X{
int z=4; } }
Keywords_var static void display(){
iables_operat System.out.println(A.X.z); }
ors_datatypes public static void main(String[] args) {
_NewQB display(); }} MCQ 4

What is the output of the following program?


public class MyClass
{
public static void main( String[] args )
{
private static final int value =9;
float total;
Keywords_var total = value + value / 2;
iables_operat System.out.println( total );
ors_datatypes }
_NewQB } MCQ 13
Keywords_var Which of the given options is similar to the
iables_operat following code: value = value
ors_datatypes + sum; sum =
_NewQB value += sum++ ; MCQ sum + 1;
What will happen if you attempt to compile and
run the following code?
Integer ten=new Integer(10);
Keywords_var Long nine=new Long (9);
iables_operat System.out.println(ten + nine);
ors_datatypes int i=1; 19 followed by
_NewQB System.out.println(i + ten); MCQ 11
Identify the statements that are correct:
Keywords_var (A) int a = 13, a>>2 = 3
iables_operat (B) int b = -8, b>>1 = -4
ors_datatypes (C) int a = 13, a>>>2 = 3
_NewQB (D) int b = -8, b>>>1 = -4 MCQ (A), (B) & (C)

Consider the following code:


int x, y, z;
y = 1;
Keywords_var z = 5;
iables_operat x = 0 - (++y) + z++;
ors_datatypes After execution of this, what will be the values x = -7, y = 1, z
_NewQB of x, y and z? MCQ =5

Here is the general syntax for method


definition:

accessModifier returnType
methodName( parameterList )
{
Java statements

return returnValue;
Keywords_var }
iables_operat It must always
ors_datatypes be private or
_NewQB What is true for the accessModifier? MCQ public

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];
String s3 = args[3];
String s4 = args[4];
System.out.print(" args[2] = " + s2);
}
}
Keywords_var
iables_operat and the command-line invocation is
ors_datatypes
_NewQB > java CommandArgs 1 2 3 4 MCQ args[2] = 2
Consider the following code snippet:
Keywords_var int i = 10;
iables_operat int n = ++i%5;
ors_datatypes What are the values of i and n after the code is
_NewQB executed? MCQ 10, 1
Keywords_var
iables_operat
ors_datatypes Which will legally declare, construct, and int [] myList =
_NewQB initialize an array? MCQ {"1", "2", "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();
t.disp(x);
System.out.println("main X="+x);
Keywords_var }
iables_operat void disp(int x) {
ors_datatypes System.out.println("disp X = "+x++); disp X = 6
_NewQB }} MCQ main X=6
How many objects and reference variables are
Keywords_var created by the following lines of code? Two objects
iables_operat Employee emp1, emp2; and three
ors_datatypes emp1 = new Employee() ; reference
_NewQB Employee emp3 = new Employee() ; MCQ variables.

A) The purpose of the method overriding is to


perform different operation, though input
Keywords_var remains the same.
iables_operat B) one of the important Object Oriented
ors_datatypes principle is the code reusability that can be Only A is
_NewQB achieved using abstraction MCQ TRUE

class Test{
public static void main(String[] args){
byte b=(byte) (45 << 1);
Keywords_var b+=4;
iables_operat System.out.println(b); }}
ors_datatypes What should be the output for the code written
_NewQB above? MCQ 48
Keywords_var What is the value of y when the code below is
iables_operat executed?
ors_datatypes int a = 4;
_NewQB int b = (int)Math.ceil(a % 3 + a / 3.0); MCQ 1
Consider the following code and choose the
correct option:
class Test{
class A{
interface X{
int z=4; } }
Keywords_var static void display(){
iables_operat System.out.println(new A().X.z); }
ors_datatypes public static void main(String[] args) {
_NewQB display(); }} MCQ

Consider the code below & select the correct


ouput from the options:
public class Test {
public static void main(String[] args) {
Keywords_var String[] elements = { "for", "tea", "too" };
iables_operat String first = (elements.length > 0) ?
ors_datatypes elements[0] : null; Compilation
_NewQB System.out.println(first); }} MCQ error

Given the following piece of code:


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

Given
class MybitShift
{
public static void main(String [] args)
{
int a = 0x5000000;
System.out.print(a + " and ");
Keywords_var a = a >>> 25;
iables_operat System.out.println(a);
ors_datatypes } 83886080 and
_NewQB } MCQ -2
Consider the code below & select the correct
ouput from the options:

public class Test {


int squares = 81;
public static void main(String[] args) {
new Test().go(); }
Keywords_var void go() {
iables_operat incr(++squares);
ors_datatypes System.out.println(squares); }
_NewQB void incr(int squares) { squares += 10; } } MCQ 92

class C{
public static void main (String[] args) {
byte b1=33; //1
b1++; //2
byte b2=55; //3
b2=b1+1; //4
Keywords_var System.out.println(b1+""+b2);
iables_operat }}
ors_datatypes Consider the code above & select the correct compile time
_NewQB output. MCQ error at line 2

What will be the output of the program ?

public class Test


{
public static void main(String [] args)
{
signed int x = 10;
Keywords_var for (int y=0; y<5; y++, x--)
iables_operat System.out.print(x + ", ");
ors_datatypes }
_NewQB } MCQ 10, 9, 8, 7, 6,

1. public class LineUp {


2. public static void main(String[] args) {
3. double d = 12.345;
4. // insert code here
5. }
6. }
Which code fragment, inserted at line 4,
produces the output | 12.345|?

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


iables_operat B. System.out.printf("|%3.7f| \n", d);
ors_datatypes C. System.out.printf("|%7.3d| \n", d);
_NewQB D. System.out.printf("|%7.3f| \n", d); MCQ A
Consider the following code and choose the
correct option:
class Test{
interface Y{
void display(); }
public static void main(String[] args) {
Keywords_var Y y=new Y(){
iables_operat public void display(){
ors_datatypes System.out.println("Hello World"); } };
_NewQB y.display(); }} MCQ Hello World

class Test{
public static void main(String[] args){
int var;
var = var +1;
Keywords_var System.out.println("var ="+var);
iables_operat }} compiles and
ors_datatypes consider the code above & select the proper runs with no
_NewQB output from the options. MCQ output

State the class relationship that is being


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

class Accounts
Keywords_var {
iables_operat public double calculateBonus(){//method's
ors_datatypes code}
_NewQB } MCQ Aggregation
Given classes A, B, and C, where B extends A,
Keywords_var and C extends B, and where all classes
iables_operat implement the instance method void doIt().
ors_datatypes How can the doIt() method in A be It is not
_NewQB called from an instance method in C? MCQ possible
Keywords_var
iables_operat
ors_datatypes Which of the following will declare an array and Array a = new
_NewQB initialize it with five numbers? MCQ Array(5);
Keywords_var
iables_operat
ors_datatypes Which of the following are correct variable
_NewQB names? (Choose TWO) MCA int #ss;
What is the output of the following:

int a = 0;
Keywords_var int b = 10;
iables_operat
ors_datatypes a = --b ;
_NewQB System.out.println("a: " + a + " b: " + b ); MCQ a: 9 b:11

As per the following code fragment, what is the


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

Consider the following code and choose the


correct output:

int value = 0;
Keywords_var int count = 1;
iables_operat value = count++ ;
ors_datatypes System.out.println("value: "+ value + " count: " value: 0
_NewQB + count); MCQ count: 0

Consider the following code and select the


correct output:
class Test{
interface Y{
void display(); }
public static void main(String[] args) {
Keywords_var new Y(){
iables_operat public void display(){
ors_datatypes System.out.println("Hello World"); } };
_NewQB }} MCQ Hello World

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;
}
for (int j = 0; j < arr.length; j++)
Keywords_var System.out.println(arr[j]);
iables_operat A sequence of
ors_datatypes } five 10's are
_NewQB } MCQ printed
Threads_New Which of the following methods registers a
QB thread in a thread scheduler? MCQ run();
class PingPong2 {
synchronized void hit(long n) {
for(int i = 1; i < 3; i++)
System.out.print(n + "-" + i + " ");
}
}
public class Tester implements Runnable {
static PingPong2 pp2 = new PingPong2();
public static void main(String[] args) {
new Thread(new Tester()).start();
new Thread(new Tester()).start();
}
public void run()
{ pp2.hit(Thread.currentThread().getId()); } The output
Threads_New } could be 5-1
QB Which statement is true? MCQ 6-1 6-2 5-2

Consider the following code and choose the


correct option:
class Cthread extends Thread{
public void run(){
System.out.print("Hi");}
public static void main (String args[]){
Cthread th1=new Cthread(); will print Hi
th1.run(); twice and
th1.start(); throws
Threads_New th1.run(); Exception at
QB }} MCQ run time

class Cthread extends Thread{


public void run(){
System.out.print("Hi");}
public static void main (String args[]){
Cthread th1=new Cthread();
th1.run();
th1.start();
Threads_New th1.start(); will start two
QB }} MCQ thread

Consider the following code and choose the


correct option:
class Cthread extends Thread{
Cthread(){start();}
public void run(){
System.out.print("Hi");}
public static void main (String args[]){ will create two
Cthread th1=new Cthread(); child threads
Threads_New Cthread th2=new Cthread(); and display Hi
QB }} MCQ twice
Threads_New Which of the following methods are defined in
QB class Thread? (Choose TWO) MCA start()
The following block of code creates a Thread
using a Runnable target:

Runnable target = new MyRunnable();


Thread myThread = new Thread(target); public class
MyRunnable
Which of the following classes can be used to implements
Threads_New create the target, so that the preceding code Runnable{pub
QB compiles correctly? MCQ lic void run(){}}

Extend
java.lang.Thre
ad and
Threads_New Which of the following statements can be used override the
QB to create a new Thread? (Choose TWO) MCA run() method.

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
{
public void run()
{
System.out.print(" Inside Runnable");
}
}
class Test
{
public static void main(String[] args)
{
new MyThread().start();
new MyThread(new MyRunnable()).start(); Prints "Inside
Threads_New } Thread Inside
QB } MCQ Thread"

A) Multiple processes share same memory


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

What will be the output of the program?

class MyThread extends Thread


{
public static void main(String [] args)
{
MyThread t = new MyThread();
t.start();
System.out.print("one. ");
t.start();
System.out.print("two. ");
}
public void run()
{
System.out.print("Thread ");
Threads_New } Compilation
QB } MCQ fails

Consider the following code and choose the


correct option:
class A implements Runnable{ int k;
public void run(){
k++; }
public static void main(String args[]){
Threads_New A a1=new A(); It will start a
QB a1.run();} MCQ new thread

Given:
public class Threads4 {
public static void main (String[] args) {
new Threads4().go();
}
public void go() {
Runnable r = new Runnable() {
public void run() {
System.out.print("run");
}
};
Thread t = new Thread(r);
t.start();
t.start();
}
Threads_New } Compilation
QB What is the result? MCQ fails.
class Thread2 {
public static void main(String[] args) {
new Thread2().go(); }
public void go(){
Runnable rn=new Runnable(){
public void run(){
System.out.println("Good Day.."); } };
Thread t=new Thread(rn);
t.start();
}}
Threads_New what should be the correct output for the code Compilation
QB written above? MCQ fails.

public class MyRunnable implements Runnable


{
public void run()
{
// some code here new
} Runnable(My
Threads_New } Runnable).sta
QB which of these will create and start this thread? MCQ rt();

Consider the following code and choose the


correct option:
class Nthread extends Thread{
public void run(){
System.out.print("Hi");} Will create
public static void main(String args[]){ two child
Nthread th1=new Nthread(); threads and
Threads_New Nthread th2=new Nthread(); display Hi
QB } MCQ twice

Assume the following method is properly


synchronized and called from a thread A on an
object B:

wait(2000);
After thread A
After calling this method, when will the thread A is notified, or
Threads_New become a candidate to get another turn at the after two
QB CPU? MCQ seconds.
Threads_New wait(), notify() and notifyAll() methods belong to
QB ________ MCQ Object class

Consider the following code and choose the


correct option:
class Test {
public static void main(String[] args) {
new Test().display("hi", 1);
strings_string new Test().display("hi", "world", 2); }
_buffer_NewQ public void display(String... s, int x) {
B System.out.print(s[s.length-x] + " "); } } MCQ hi hi
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
strings_string String name="Anthony Gomes";
_buffer_NewQ int a=111;
B System.out.println(name.indexOf(a)); }} MCQ 4
Given:
String test = "This is a test";
strings_string String[] tokens = test.split("\s");
_buffer_NewQ System.out.println(tokens.length);
B What is the result? MCQ

Consider the following code and choose the


correct option:
public class Test {
strings_string public static void main(String[] args) {
_buffer_NewQ String data="78";
B System.out.println(data.append("abc")); }} MCQ 78abc

Consider the following code and choose the


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

Examine this code:

String stringA = "Hello ";


String stringB = " World";
String stringC = " Java"; result =
strings_string String result; stringA.concat
_buffer_NewQ Which of the following puts a reference to ( stringB.conc
B "Hello World Java" in result? MCQ at( stringC ) );

For two string objects obj1 and obj2:


A) Use of obj1 == obj2 tests whether two String
strings_string object references refer to the same object
_buffer_NewQ B) obj1.equals(obj2) compares the sequence of Only A is
B characters in obj1 and obj2. MCQ TRUE

What is the result of the following:

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


String find = "One ring to find them.";

if ( ring.startsWith("One") &&
find.startsWith("One") ) One ring to
strings_string System.out.println( ring+find ); rule them all,
_buffer_NewQ else One ring to
B System.out.println( "Different Starts" ); MCQ find them.
The code will
Consider the following code and choose the fail to compile
correct option: because the
class MyClass { expression
String str1="str1"; str3.concat(str
String str2 ="str2"; 1) will not
String str3="str3"; result in a
str1.concat(str2); valid
strings_string System.out.println(str3.concat(str1)); argument for
_buffer_NewQ } the println()
B } MCQ method

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

StringBuffer sb1 = new StringBuffer("abc");


StringBuffer sb2 = sb1;
sb1.append("d");
System.out.println(sb1 + " " + sb2 + " " +
(sb1==sb2));
strings_string }
_buffer_NewQ } Compilation
B Which are true? (Choose all that apply.) MCA fails

class StringManipulation{
public static void main(String[] args){
String str = new String("Cognizant");
str.concat(" Technology");
StringBuffer sbf = new StringBuffer("
Solutions");
System.out.println(str+sbf);
strings_string }} Cognizant
_buffer_NewQ consider the code above & select the proper Technology
B output from the options. MCQ Solutions

What does this code write:

StringTokenizer stuff = new


strings_string StringTokenizer( "abc def+ghi", "+");
_buffer_NewQ System.out.println( stuff.nextToken() );
B System.out.println( stuff.nextToken() ); MCQ abc def
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
StringBuffer sb = new
strings_string StringBuffer("antarctica");
_buffer_NewQ sb.delete(0,6);
B System.out.println(sb); }} MCQ tica

Consider the following code and choose the


correct option:
public class Test {
public static void main(String[] args) {
strings_string String name="vikaramaditya";
_buffer_NewQ System.out.println(name.substring(2,
B 5).toUpperCase().charAt(2));}} MCQ K

Consider the following code and choose the


correct option:
public class Test {
public static void main(String[] args) {
StringBuffer sb = new
StringBuffer("antarctica");
sb.reverse();
strings_string sb.replace(2, 7, "c");
_buffer_NewQ sb.delete(0,2);
B System.out.println(sb); }} MCQ acctna

Consider the following code and choose the


correct option:
class Test {
public static void main(String args[]) {
String s1 = "abc";
strings_string String s2 = "def";
_buffer_NewQ String s3 = s1.concat(s2.toUpperCase( ) );
B System.out.println(s1+s2+s3); } } MCQ abcdefabcdef

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

public void amethod(String s){


char c='H';
c+=s;
strings_string System.out.println(c); Compilation
_buffer_NewQ } and output the
B } MCQ string "Hello"
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) {
strings_string String name="Anthony Gomes";
_buffer_NewQ System.out.println(name.replace('n',
B name.charAt(3)).compareTo(name)); }} MCQ -6

Consider the following code and choose the


correct option:
class Test {
public static void main(String args[]) {
String name=new String("batman");
int ibegin=1;
char iend=3;
strings_string System.out.println(name.substring(ibegin,
_buffer_NewQ iend));
B }} MCQ bat

Consider the following code and choose the


correct option:
public class Test {
public static void main(String[] args) {
strings_string StringBuffer sb=new
_buffer_NewQ StringBuffer("YamunaRiver");
B System.out.println(sb.capacity()); }} MCQ 10

Consider the following code and choose the


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

Examine this code:

String stringA = "Wild";


String stringB = " Irish";
String stringC = " Rose";
String result; result =
strings_string stringA.concat
_buffer_NewQ Which of the following puts a reference to "Wild ( stringB.conc
B Irish Rose" in result? MCQ at( stringC ) );
Consider the following code and choose the
correct option:
class Test {
public static void main(String[] args) {
new Test().display(1,"hi");
strings_string new Test().display(2,"hi", "world" ); }
_buffer_NewQ public void display(int x,String... s) {
B System.out.print(s[s.length-x] + " "); }} MCQ hi hi

Consider the following code and choose the


correct option:
public class Test {
public static void main(String[] args) {
strings_string String name="vikaramaditya";
_buffer_NewQ System.out.println(name.codePointAt(2)+name.
B charAt(3)); }} MCQ 203

Consider the following code and choose the


correct option:
public class Test {
strings_string public static void main(String[] args) {
_buffer_NewQ String data="7882";
B data+=32; System.out.println(data); }} MCQ 7914

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";
// Line X
{
System.out.println("Equal");
}else
{
System.out.println("Not equal");
strings_string }
_buffer_NewQ }
B } MCQ if(s==s2)
import java.io.*;
public class MyClass implements Serializable {
private int a;
public int getA() { return a; }
publicMyClass(int a){this.a=a; }
private void writeObject( ObjectOutputStream
s)
throws IOException {
// insert code here
}
}

Which code fragment, inserted at line 15, will


IO_Operation allow Foo objects to be
s_NewQB correctly serialized and deserialized? MCQ s.writeInt(x);

FileOutputStre
am fos = new
Which of the following opens the file FileOutputStre
IO_Operation "myData.stuff" for output first deleting any file am( "myData.
s_NewQB with that name? MCQ stuff", true )

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

private Tree tree = new Tree();

public static void main(String [] args) {


MyClass mc= new MyClass();
try {
FileOutputStream fs = new
FileOutputStream(”MyClass.ser”);
ObjectOutputStream os = new
ObjectOutputStream(fs);
os.writeObject(mc); os.close();
IO_Operation } catch (Exception ex) { ex.printStackTrace(); } Compilation
s_NewQB }} MCQ fails
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 {
File file=new File("d:/std.txt");
FileOutputStream fos=new
FileOutputStream(file);
ObjectOutputStream oos=new
ObjectOutputStream(fos);
std s1=new std(10); the state of
oos.writeObject(s1); the object s1
IO_Operation oos.close(); will be store to
s_NewQB }} MCQ file std.txt

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"); reads data
byte buffer[]=new byte[(int)file.length()+1]; from file one
FileInputStream fis=new FileInputStream(file); byte at a time
int ch=0; and display it
IO_Operation while((ch=fis.read())!=-1){ on the
s_NewQB System.out.print(ch); } }} MCQ console.

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"); reads data
byte buffer[]=new byte[(int)file.length()+1]; from file one
FileInputStream fis=new FileInputStream(file); byte at a time
int ch=0; and display it
IO_Operation while((ch=fis.read())!=-1){ on the
s_NewQB System.out.print((char)ch); } }} MCQ console.

Consider the following code and choose the


correct option:
public class Test {
public static void main(String[] args) { creates
IO_Operation File file=new File("d:/prj/lib"); directory
s_NewQB file.mkdirs();}} MCQ d:/prj/lib
Consider the following code and choose the
correct option:
public class Test {
public static void main(String[] args) throws
IOException {
String data="Confidential info";
byte buffer[]=data.getBytes();
FileOutputStream fos=new
FileOutputStream("d:/temp"); writes data to
IO_Operation for(byte d : buffer){ file in byte
s_NewQB fos.write(d); } }} MCQ form.

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)
System.out.println(s);
br.flush();
} catch (IOException e) { System.out.println("io
error"); }
}
}
And given that myfile.txt contains the following
two lines of data:
ab
IO_Operation cd
s_NewQB What is the result? MCQ ab

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 {
File file=new File("d:/std.txt");
FileOutputStream fos=new
FileOutputStream(file);
ObjectOutputStream oos=new
ObjectOutputStream(fos);
std s1=new std(10); the state of
oos.writeObject(s1); the object s1
IO_Operation oos.close(); will be store to
s_NewQB }} MCQ file std.txt
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]; reads data
FileInputStream fis=new FileInputStream(file); from file
fis.read(buffer); named jlist.lst
System.out.println(buffer); in byte form
IO_Operation } and display it
s_NewQB } MCQ on console.

Consider the following code and choose the


correct option:
public class Test {
public static void main(String[] args) throws
IOException { reads data
File file=new File("D:/jlist.lst"); from file
byte buffer[]=new byte[(int)file.length()+1]; named jlist.lst
FileInputStream fis=new FileInputStream(file); in byte form
IO_Operation fis.read(buffer); and display it
s_NewQB System.out.println(new String(buffer)); }} MCQ on console.

throws a
IO_Operation What happens when the constructor for DataFormatEx
s_NewQB FileInputStream fails to open a file for reading? MCQ ception

Consider the following code and choose the


correct option:
public class Test { creates
public static void main(String[] args) { directories
IO_Operation File file=new File("d:/prj,d:/lib"); names prj and
s_NewQB file.mkdirs();}} MCQ lib in d: drive

Consider the following code and choose the


correct output:
public class Person{
public void talk(){ System.out.print("I am a
Person "); }
}
public class Student extends Person {
public void talk(){ System.out.print("I am a
Student "); }
}
what is the result of this piece of code:
public class Test{
public static void main(String args[]){
Person p = new Student();
p.talk();
IO_Operation }
s_NewQB } MCQ I am a Person
Which of these are two legal ways of accessing
a File named "file.tst" for reading. Select the
correct option:
A)FileReader fr = new FileReader("file.tst");
B)FileInputStream fr = new
FileInputStream("file.tst");
C)InputStreamReader isr = new
InputStreamReader(fr, "UTF8");
IO_Operation D)FileReader fr = new FileReader("file.tst",
s_NewQB "UTF8"); MCQ A,D
What is the DataOutputStream method that
IO_Operation writes double precision floating point values to
s_NewQB a stream? MCQ writeBytes()

Consider the following code and choose the


correct option:
public class Test{
public static void main(String[] args) {
File dir = new File("dir");
dir.mkdir();
File f1 = new File(dir, "f1.txt"); try { The file
f1.createNewFile(); } catch (IOException e) { ; system has a
} new empty
IO_Operation File newDir = new File("newDir"); directory
s_NewQB dir.renameTo(newDir);} } MCQ named dir

Consider the following code and choose the


correct option:
public class Test {
public static void main(String[] args) throws
IOException {
File file=new File("d:/data");
byte buffer[]=new byte[(int)file.length()+1];
FileInputStream fis=new FileInputStream(file); Transfer
fis.read(buffer); content of file
IO_Operation FileWriter fw=new FileWriter("d:/temp.txt"); data to the
s_NewQB fw.write(new String(buffer));}} MCQ temp.txt
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class MoreEndings {
public static void main(String[] args) {
try {
FileInputStream fis = new
FileInputStream("seq.txt");
InputStreamReader isr = new
InputStreamReader(fis);
int i = isr.read();
while (i != -1) {
System.out.print((char)i + "|");
i = isr.read();
}
} catch (FileNotFoundException fnf) {
System.out.println("File not found");
} catch (EOFException eofe) {
System.out.println("End of stream");
} catch (IOException ioe) {
System.out.println("Input error");
} The program
} will not
} compile
Assume that the file "seq.txt" exists in the because a
current directory, has the required certain
access permissions, and contains the string unchecked
IO_Operation "Hello". exception is
s_NewQB Which statement about the program is true? MCQ not caught.

Consider the following code and choose the


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

A file is readable but not writable on the file


system of the host platform. What will A
IO_Operation be the result of calling the method canWrite() SecurityExcep
s_NewQB on a File object representing this file? MCQ tion is thrown
Introduction_t void add(int
o_OOPS_Ne Which of following set of functions are example x,int y) char
wQB of method overloading MCQ add(int x,int y)
Efficient
Introduction_t utilization of
o_OOPS_Ne What is the advantage of runtime memory at
wQB polymorphism? MCQ runtime
Introduction_t
o_OOPS_Ne Which of the following is an example of IS A
wQB relationship? MCQ Ford - Car
Introduction_t
o_OOPS_Ne Which of the following is not a valid relation
wQB between classes? MCQ Inheritance
Introduction_t
o_OOPS_Ne Which of the following is not an attribute of
wQB object? MCQ State
Choice2 Choice3 Choice4 Choice5 Grade1 Grade2 Grade3

A compilation
error will
occur at (Line
A compilation no 2), since
error will the class does
occur at (2), not have a
since the constructor
class does not that takes one The program
have a default argument of will compile
constructor type int. without errors. 0 0 0

String s = int i = new


byte b = 256; “null”; Integer(“56”); 0 0 0.5

The compiler
The code will will complain
compile but that the
The compiler complain at method
will complain run time that myfunc in the
that the Base the Base base class
class has non class has non has no body,
abstract abstract nobody at all
methods methods to print it 1 0 0

Constructor of Constructor of Constructor of


C executes C executes A executes
first followed first followed first followed
by the by the by the
constructor of constructor of constructor of
A and B B and A C and B 1 0 0
Compiles and Compiles but Compiles and
display 1 no output diplay 0 1 0 0

The
returnValue
must be the
same type as
the
returnType, or The
If the be of a type returnValue
returnType is that can be must be
void then the converted to exactly the
returnValue returnType same type as
can be any without loss of the
type information returnType. 0 0 1

Both are Only A is Only B is


TRUE TRUE TRUE 0 1 0

Compiles but
throws
Comiples and runtime Compiles and
prints From A exception display 3 0 1 0
1 2 100 100 10 20 1 2 100 1 2 10 20 100
10 20 100 100 0 0 0

Compiles but
Compiles and doesn't
throw run time display Compilation
exception anything fails 1 0 0

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

Compiles but Compiles and


throws run displays None of the
time exception nothing listed options 1 0 0
compiles but does not
Runtime Error no output compile 0 0 0

100 followed Compile time


by 200 error 100 0 0 1

int: 27, String:


Int first String:
String first, int: Compilation Runtime
27 Error Exception 1 0 0
B and C is
All are TRUE TRUE All are FALSE 0 0 1

Compiles and Compiles but


prints throws
Display() runtime Compilation
show() exception error 0 1 0

Only A is
All are TRUE All are FALSE TRUE 0 0 0

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

System.out.pri System.out.pri System.out.pri


ntln(Math.floor ntln(Math.roun ntln(Math.min(
(-4.7)); d(-4.7)); -4.7)); 1 0 0
Only A is Only A and C
TRUE All are FALSE is TRUE 1 0 0

Dog Man Cat


Ant Man Dog Ant Dog Man Ant 1 0 0

Compiles and
throws run Compilation Compiles and
time exception fails displays Hi 0 0 1

Compiler Runs but no


Error output Runtime Error 0 1 0
sp.methodRa Nothing to Sphere.metho
dius(x); add dRadius(); 0 1 0

compiles
successfully
but runtime
error compile error none of these 0 0 1

Compiles and Compiles but


prints throws
Display() runtime Compilation
show() exception error 0 0 0

Compiles and
runs without Compiles and Compiles and
any output display 2 display 0 0 0 1
0,0 compile error runtime error 1 0 0

It is not
possible to
access a
static variable
Compilation Garbage in side of non
Error Value static method 1 0 0
default zero
default default zero one two 0 0 1

this = new this.suns =


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

public transient synchronized 0 0 0


Cheese()
Meal() Meal() Sandwich()
Cheese() Lunch() Meal()
Lunch() PortableLunch Lunch()
PortableLunch () Sandwich() PortableLunch
() Sandwich() Cheese() () 1 0 0

compilation Compiles and Compiles and


error display 4 display 3 1 0 0
20 and 40 10 and 40 10, and 20 0 0 1

The program
The compiler will compile
will find the The program successfully,
error and will will compile but the .class
not make a and run file will not run
.class file successfully correctly 0 1 0

1 2 3 0 0 0
Cat Ant Dog Dog Man Cat
Man Ant compile error 0 0 1

Compilation
Error occurs
and to avoid
A Sequence them we need
of 5 one's will to declare
be printed like IndexOutOfBo Mine class as
11111 undes Error abstract 0 0 0

Compiler
Error: size of
array must be
2 1 defined 0 1 0

false 0 1

Compiles and Compiles and Compiles but


display 0 display 23 no output 1 0 0
It is not
possible to
declare a
constructor as Compilation Runs without
private Error any output 0 0 1

Runtime
Exception 2500 50 0 0 1

It is not
possible to
declare a
static variable
in side of non
static method
or instance
method.
Because
Static
Compile time variables are
error because Compilation class level
i has not been and output of dependencies
initialized null . 0 0 0
Unresolved
compilation
problem: The
local variable
i1 may not Compilation
have been and output of None of the
initialized null given options 0 1 0

It is not Can't create


possible to object
declare a because
constructor Compilation constructor is
private Error private 1 0 0

volatile transient default 0 1 0


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

Compiles and
runs without Compiles and Compilation
any output display 0 error 0 0 0

Dog Cat Ant Ant Cat Dog none 0 1 0


A compile
A random A random time error as
number number random being
between 1 between 0 an undefined
and 10 and 1 method 1 0 0

Retention Depricated Documented Target 0 0.333333 0

class source runtime 0 1 0

CONSTRUCT
METHOD RUNTIME OR CLASS 0.333333 0 0.333333
Compile time
and
Information for deploytime Runtime Information for
the JVM processing processing the OS 0.333333 0 0.333333

false 0 1
all the listed
@inherit @include options 1 0 0

Compilation Compilation
The code runs An exception fails because fails because
with no is thrown at of an error in of an error in
output. runtime line 21 line 23. 1 0 0
An exception
Compilation is thrown at
B, C, A, fails. runtime. 0 1 0

The program The program


will compile will compile
and print the and throw a The program
following runtime will not
output: [B,A] exception compile 0 0 1

The before()
method will
The before() throw an The before()
method will exception at method will
print 1 2 3 runtime not compile 0 0 1

Today is none of the


Holiday Both listed options 0 1 0
The code runs
Compilation with no
1, 2, 3, fails. output. 0 0 1

java.util.Linke java.util.Array java.util.Vecto


dHashSet java.util.List List r 0 0 0

none of the
-1 listed options 0 1 0

2 3 4 0 0 1

Compiles but
exception at
prints 3,4,2,1, prints 1,2,3,4 runtime 0 0 1
tSetdelete(ne tSet.remove(n
w ew tSet.drop(new
Integer("1")); Integer("1")); Integer("1")); 0 0 1

3 -5 2 -6 3 -4 0 0 1

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

Long int String 0 0 0


Compile time Runtime
false error Exception 0 1 0

A and D is A and C is B and D is


TRUE TRUE TRUE 0 0 1
Java.util.Colle
Java.util.List Java.util.Table ction 1 0 0

none of the
-1 null listed options 0 0 1

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


[8,6,4,9] [4,6,8,9] [4,6,8] 0 0 1
A and D is A and C is B and D is
TRUE TRUE TRUE 0 0 1
Collections ArrayList
class Vector class class 0 1 0
ArrayList Collection Collections
class interface class 0 0 0

java.util.Tree java.util.TreeS java.util.Hasht


Map et able 0 0 0

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


aAaA aAa AAaa AaA AaA AAaa
AAaa AaA aAa aAaA aAaA aAa 0 0 1

A and D is A and C is B and C is


TRUE TRUE TRUE 0 0 0

The size of s The size of The size of s The size of


is 5 subs is 3 is 7 subs is 1 0 0.5 0.5

244 JUN 01 PST JUN 01 GMT JUN 01


1983 1983 1983 1 0 0
12 14 1 0 0 1

2 3 4 0 0 0

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


Compiles but
compilation error at run
5 error time 0 1 0

Compilation
000120 00012021 error 0 1 0

Compilation
harrier fails. collie harrier 0 0 0

compilation
false error Compiles 0 1 0
NumberForma
2.147483648 tException at Compiles but
E9 run time no output 0 0 1

Compilation
shepherd retriever fails. 0 0 0

21 22 23 24 0 0 1

3 <= r <= 10 2<= r <= 10 3 <= r <= 9 1 0 0


none of the
C.H.Gayle Compile error listed options 0 0 1

24 234 246 0 1 0

Compiles but
Three Five no output 1 0 0

82 91 92 0 1 0
If a is false If a is false
If a is true and and b is false and b is true
b is true then then the then the
the output is output is output is
"A && B" "ELSE" "ELSE" 0 0 0

Compilation
28 Error 10 Runtime Error 0 0 1
There are There are
syntax errors syntax errors There is a
on lines 1 and on lines 1, 6, syntax error
6 and 8 on line 6 0 0 0

Compilation
s++; s = s + s * i; s *= i; error 0 0 0

Double has a Character has String is the


compareTo() a intValue() Byte extends wrapper class
method method Number of char 0 0.5 0

atom granite atom granite


granite granite granite atom granite 0 0 0
Integer, new Integer, int int, Integer 0 1 0

value = 2 value = 4 value = 6 1 0 0

Compilation
hi world world world fails. 0 0 0
Compiles but
compilation error at run
46 error time 1 0 0

b= b= b=
nf.format( inpu nf.equals( inp nf.parseObjec
t ); ut ); t( input ); 0 1 0

3211 2211 4211 1 0 0

Compiles but
Compilation error at run None of the
error time listed options 0 1 0

No, Runtime
error Yes, 10, 100 Yes, 100, 100 0 0 0
true false 1 0 0 1

2 4 1 0 0 0

The code will


fail to compile
because the
compiler will
not be able to The code will The code will
determine compile compile The code will
which if correctly and correctly and compile
statement the display the display the correctly,but
else clause letter a,when letter b,when will not display
belongs to run run any output 0 0 0

good morning
morning …. compiler error runtime error 0 0 1
Compilation bat man
error spider man spider man 0 0 1

Compilation
32 25 Error Runtine Error 0 0 1

four three two four one three one two three


one two four one 0 0 1

3 23 123 0 0 1
ArrayList is a LinkedList is a Stack is a
sub class of subclass of subclass of
Vector ArrayList Vector 0.5 0 0

[608, 610,
[608, 610, An exception 612, 629]
612, 629] is thrown at [608, 610,
[608, 610] runtime. 629] 0 0 1

bad compile error run time error 0 0 1

default compilation
brownie error default 1 0 0
5 7 9 11 0 0 0

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

0001 000120 00012021 0 0 1


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

Compilation Compilation
012122 fails at line 11 fails at line 12. 0 0 1

5,5 6,5 6,6 0 1 0


none of the
runtime error compiler error listed options 0 0 1

5,5 6,5 6,6 0 1 0

Compiles but
Compilation error at run None of the
error time listed options 0 1 0

tall short short very short average 0 1 0


Compiles but
error at run
1515 255 time 0 0 1

Compilation
j=0 j=1 fails 0 0 0

Person p[][] =
new Person[2]
Person p[5]; Person[] p []; []; 0 1 0

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


false, true true, false true, true 0 0 1
An exception
Compilation is thrown at
r, e, o, fails. runtime. 0 0 1

The code runs


Compilation with no
x=3 fails. output. 0 0 1

tset.headset headSet HeadSet 1 0 0


compilation
default apple error default 1 0 0

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

You lose the


prize. You win You lose 1 0 0

Changes
made in the
Set view
returned by The Map
keySet() will interface All Map
be reflected in extends the All keys in a implementatio
the original Collection map are ns keep the
map interface unique keys sorted 0 0.5 0

HashSet Vector LinkedList ArrayList 0 0 0


To write
characters to
an
Subclasses of outputstream, To write an
the class you have to object to a file,
Reader are make use of you use the
used to read the class class
character CharacterOut ObjectFileWrit
streams. putStream. er 0.5 0.5 0

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

If a variable of
type int
overflows
during the
An overflow execution of a
error can only A loop may loop, it will
occur in a have multiple cause an
loop exit points exception 0 0 1

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


When an
exception When no
occurs then a exception
part of try occurs then
block will complete try
execute one block and
appropriate finally block finally block
catch block will never will execute
Writing finally and finally execute when but no catch
block is block will be no exceptions block will
optional. executed. are there. execute. 0.25 0.25 0.25

A run time
error
indicating that Clean compile
no run method and at run
is defined for time the Clean compile
the Thread values 0 to 9 but no output
class are printed out at runtime 0 0 0

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

A thread will Both wait()


The wait() resume The notify() and notify()
method is execution as method is must be called
overloaded to soon as its overloaded to from a
accept a sleep duration accept a synchronized
duration expires. duration context. 0 0.33 0.33
The program
will print Hello The program
world, then The program will print Hello
will print that a will print Hello world, then
RuntimeExce world, then will print
ption has will print that a Finally
occurred, then RuntimeExce executing,
will print Done ption has then will print
with try block, occurred, and that a
and then will then will print RuntimeExce
print Finally Finally ption has
executing. executing. occurred. 0 0 0

true 0 1

Only B is Bothe A and B Both A and B


TRUE is TRUE is FALSE 0 0 1
hello throwit
RuntimeExce
hello throwit ption caught Compilation
caught after fails 1 0 0

Cannot
Compilation determine prints 12 12
Error output. 12 12 0 0 0
A try block
cannot be A finally block
followed by must always
both a catch An empty A catch block follow one or
and a finally catch block is cannot follow more catch
block not allowed a finally block blocks 0 0 0

test runtime test exception test exception


end runtime end end 0 0 0

A method
declaring that
it throws a
An overriding certain
method must exception Finally blocks
declare that it The main() class may are executed
throws the method of a throw if,an exception
same program can instances of gets thrown
exception declare that it any subclass while inside
classes as the throws of that the
method it checked exception corresponding
overrides exception class try block 0 0 0.5
2, 3, 4 and 5 1, 4, 5 and 6 2, 4, 5 and 6 0 0 1

X run = new
Thread t = X(); Thread t =
new new Thread t =
Thread(X); Thread(run); new Thread();
t.start(); t.start(); x.run(); 0 0 1

No output,
and an X, followed by
Exception is an Exception,
thrown. followed by B. none 1 0 0
compilation ArithmeticExc
Exception fails eption 0 0 1

join() yield() sleep() 0 0 0.5

static methods
can be called static methods
using an do not have
object direct access
reference to static methods to non-static
an object of are always methods
the class in public, which are
which this because they defined inside
method is are defined at the same
defined. class-level. class. 0 0.5 0

exit
RuntimeExce
ption thrown Compilation
exit at run time fails 0 0 1
Exception
occurred
RuntimeExce RuntimeExce does not
ption ption compile 0 0 0

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

NumberForma IllegalStateEx IllegalArgume


tException ception ntException 0 0.5 0

One Catch One Two


One Catch Finally Catch 0 0 1
The program The program The program The program
will only print will only print will only print will only print
1 and 4 in 1,2 and 4 in 1 ,4 and 5 in 1,2,4 and 5 in
order order order order 0 0 0

We cannot
have a try
We cannot block block
have a try without a
block without catch / finally Nothing is
a catch block block diaplayed 0 0 1

An exception
Compilation is thrown at
meow fails runtime. peep 0 0 0
Thread t =
Thread t = Thread t = new
new new Thread(); Thread(X);
Thread(X); x.run(); t.start(); 1 0 0

Variables can
be protected
If a class has from
synchronized concurrent
code, multiple access
threads can problems by
still access marking them When a
the with the thread sleeps,
nonsynchroniz synchronized it releases its
ed code. keyword. locks 0 1 0

Compiles but
Compiles and Compilation exception at
no output fails runtime 0 0 1

throws
throws throw RuntimeExce
Exception Exception ption 0 1 0
Implement Extend
Extend java.lang.Thre java.lang.Run Implement
java.lang.Thre ad and nable and java.lang.Thre
ad and implement the override the ad and
override the start() start() implement the
run() method. method. method. run() method. 0.5 0.5 0

An Error that Except in


might be case of VM
thrown in a shutdown, if a
Multiple catch method must try block starts
statements be declared to execute, a
can catch the as thrown by corresponding
same class of that method, finally block
exception or be handled will always
more than within that start to
once. method. execute. 0 0 0

Arithmetic
Exception
Runtime Runtime compilation
Exception Exception error 1 0 0

Compilation finally
fails. exception finally 0 0 1
Compilation Compilation Compilation
5 followed by fails with an fails with an fails with an
an exception error on line 7 error on line 8 error on line 9 0 0 0

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

Any statement
Any statement that can throw
The Error that can throw an Exception
class is a an Error must must be
RuntimeExce be enclosed in enclosed in a
ption. a try block. try block. 1 0 0
does not none of the
compile runtime error listed options 0 0 1

hello throwit
RuntimeExce hello throwit
Compilation ption caught caught finally
fails after after 0 0 0

synchronized final private 0 1 0

NumberForma
tException ParseExceptio
thrown at Compilation n thrown at
runtime fails runtime 0 0 1
A A
ParseExceptio NumberForma
n is thrown by tException is
the parse thrown by the
Compilation method at parse method
fails runtime. at runtime. 0 1 0

If run with one


If run with one arguments,the
If run with no The program arguments,the program will
arguments,the will throw an program will print the given
program will ArrayIndexOut simply print argument
produce "The OfBoundsExc the given followed by
end" eption argument "The end" 0 0.5 0

NullPointerEx NoClassDefF NumberForma


ception oundError tException 0 0 0
ArrayIndexOut
NullPointerEx OfBoundsExc
IOException ception eption 0 1 0

Compilation Compilation
fails because fails because
of an error in of an error in
A,B,Exception line 20. line 14. 0 0 0
The notify()
The notify() method
method is causes a
To call sleep(), defined in thread to
a thread must class immediately
own the lock java.lang.Thre release its
on the object ad locks. 1 0 0

Try Block Finally Block


Finally Block Finally Block Try Block 0 1 0

End of End of
run method. method. run.
java.lang.Runt java.lang.Runt java.lang.Runt
imeException: imeException: imeException:
Problem Problem Problem 0 0 0

Unchecked
exceptions Exception all of these 0 1 0

Compiles but
Compilation error at run
error time 0 0 1
Declaring the
Synchronizing doThings()
the run() method as
method would static would
make the make the An exception
class thread- class thread- is thrown at
safe. safe. runtime. 0 0 1

Compiles but
Compilation exception at
exit fails runtime 0 0 0

An object will
not be
garbage
collected as
The finalize() long as it
The finilize() method will possible for a The garbage
method will never be live thread to collector will
eventually be called more access it use a mark
called on than once on through a and sweep
every object an object reference. algorithm 0 0 0.5

B C D 0 0 1
Only the
garbage
collection
system can
Runtime.getR destroy an
x.finalize() untime().gc() object. 0 0 0

1 2 3 0 0 1

none of the
Thi is java This i java Thi i java listed options 0 0 0

Call
System.gc()
passing in a
reference to Garbage
the object to collection
be garbage Call Call cannot be
collected System.gc() Runtime.gc(). forced 0 0 0
1 2 3 0 1 0

Create an
Compile time object for
error Interface only Runtime Error 0 1 0
This is a final
method Some Compilation illegal Some
error message error error message 0 0 1

B C D 0 0 0
Compilation
4, 5 5, 4 fails 0 0 0

Compilation
47 7 0 error 47 47 47 0 0 0
A a2=(B)c; C c2=(C)(B)c; A a1=(Test)c; 0 0 0

The code will


fail to compile
because a call The code will The code will
to a max() compile and compile and
method is print 23, when print 29, when
ambiguous. run. run. 0 0 0

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


abstract class
AllMath
implements
DoMath,
interface MathPlus
AllMath { public class AllMath
implements double implements
MathPlus getArea(int MathPlus
{ double rad) { return { double
getVol(int x, rad * rad * getArea(int
int y); } 3.14; } } rad); } 0 0 1

Compiles but
Compilation error at
error sum of int7 runtime 0 0 1

Compiles but
Compilation error at run Runs but no
error time output 0 1 0

generic noise bark compile error 1 0 0


sal details per compilation per details sal
details error details 0 0 0

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

No—a Yes—the
variable must variable can
always be an refer to any
object No—a object whose
reference type variable must class
or a primitive always be a implements
type primitive type the interface 0 0 0

Compiles but
compilation error at
4 error runtime 0 0 1
The statement The statement
The statement a.j = 5; is The statement b.i = 3; is
b.f(); is legal legal. a.g(); is legal legal. 0.333333 0.333333 0

final double
circumference protected int
= 2 * Math.PI CODE = int AREA = r * public static
* r; 31337; s; MAIN = 15; 0 0.5 0

compile time
error hello hellohello 0 1 0

Compiles but
Compilation error at run
error time null 0 1 0
we must use
always
implements
and later we we can use in extends and
must use any order its implements
extends not at all a can't be used
keyword. problem together 1 0 0

A,C,D B,D,E C,D,E 0 1 0

Compilation
s 16 s 10 fails. 0 0 0
If you define D If you define D
e = (D) (new e = (D) (new
E()), then E()), then
e.methodB() e.methodB()
invokes the invokes the
version of Compilation version of
methodB() fails, due to methodB()
defined at line an error in line defined at line
9 7 5 0 1 0

It must be It must be
used in the used in the
Only one child last statement first statement
class can use of the of the
it constructor. constructor. 0 0 0

Compiles but
Compilation error at run Runs but no
error time output 0 1 0

Compiles but
Compilation error at
error Hello B runtime 0 0 0
Definitely
legal at Definitely
Legal at runtime, but legal at
compile time, the cast runtime, and
but might be operator (Sub) the cast
illegal at is not strictly operator (Sub)
runtime needed. is needed. 0 1 0

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

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

Compiles but
Compilation error at
error Hello B runtime 0 0 1
Because of
single Because of Because of
inheritance, single single
Mammal can inheritance, inheritance,
have no other Animal can Mammal can
parent than have only one have no
Animal subclass siblings. 0 1 0

generic noise bark compile error 0 0 1

100 followed
200 by 200 100 0 0 1
compile error runtime error none 0 1 0

The statement
a.j = 5; is The statement The statement
legal. b.f(); is legal. a.g(); is legal. 0.333333 0 0.333333

cannot call
by creating an because it is
instance of overridden in
this keyword the base class derived class 1 0 0

Compiles but
error at run
time 90 mph 150 mph 1 0 0
A
The code runs NullPointerEx
Cannot add with no ception is
Toppings output. thrown 1 0 0

Compiles but
Compilation error at run Runs but no
error time output 0 1 0

private final public static


final static int static int int answer =
answer = 42; answer = 42; int answer; 42; 0.25 0.25 0.25

No—but a
object of Yes—an
parent type object can be Yes—any
can be assigned to a object can be
assigned to a reference assigned to
variable of variable of the any reference
child type. parent type. variable. 0 0 1
If both a If neither
subclass and super() nor
its superclass this() is Calling
do not have declared as super() as the
any declared the first If super() is first statement
constructors, statement in the first in the body of
the implicit the body of a statement in a constructor
default constructor, the body of a of a subclass
constructor of this() will constructor, will always
the subclass implicitly be this() can be work, since all
will call inserted as declared as superclasses
super() when the first the second have a default
run statement. statement constructor. 0 1 0

static final final data type


static data data type variablename
type variable; varaiblename; =intialization; 1 0 0

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

Bicycle Auto compile error runtime error 0 0 1


sal details per compilation per details sal
details error details 0 0 1

public and public ,static default and


abstract and final abstract 0 0 1

Compiles but
Compilation error at run Runs but no
error time output 0 1 0

An abstract
class is one
which
contains some
defined An abstract
methods and class is one
some which Abstract class
undefined contains only can be
methods static methods declared final 0.5 0.5 0

abstract class
Vehicle
abstract class abstract { abstract void abstract class
Vehicle Vehicle display(); Vehicle
{ abstract void { abstract void { System.out.p { abstract void
display(); } display(); } rintln("Car"); }} display(); } 0 0 0
Compiles but
Compilation error at run Compiles but
error time no output 1 0 0

Compilation of Compilation of
class A will class B will
fail. fail.
Compilation of Compilation of Compilation of
both classes class B will class A will
will succeed succeed succeed 0 0 0

Yes— either
of the two
variables can
No—a class be accessed Yes—since
may not through : the definitions
implement interfaceNam are the same
more than one e.variableNam it will not
interface e matter 0 0 1
An overriding The
method can parameter list
declare that it of an
throws overriding
checked method can The overriding
exceptions be a subset of method must
A subclass that are not the parameter have different
can override thrown by the list of the return type as
any method in method it is method that it the overridden
a superclass overriding is overriding method 1 0 0

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

Helps the
compiler to
find the
source file
that
corresponds
to a class, Helps
when it does Helps JVM to Javadoc to
not find a find and build the Java
class file while execute the Documentatio
compiling classes n easily 0 1 0

Holds the
Holds the location of
location of User Defined
Java classes, Holds the
Extension packages and location of
Library JARs Java Software 0 0 1
Class and
Interfaces in
the sub
packages will
be
Sub packages automatically
Packages can Packages can should be available to
contain both contain non- declared as the outer
Classes and java elements private in packages
Interfaces such as order to deny without using
(Compiled images, xml importing import
Classes) files etc. them statement. 0 0.5 0.5

String args String[] args[] String[] args


String
. args[] 0 0 0
p@ckage.sub package.subp
_score.pack._ p@ckage.inne ackage.innerp
$$.$$.$$ _pack rp@ckage ackage 0.333333 0.333333 0.333333

Object class
Object class provides the
has the core method for Object class
Object class methods for Set implements
cannot be thread implementatio Serializable
instantiated synchronizatio n in Collection interface
directly n framework internally 0 0 0.5
Java
Java Runtime Database
Environment Connectivity Java
(JRE) (JDBC) Debugger 0 1 0
registerDriver(
) method and
Class.forNam Class.forNam
e() e() getConnection 0 0 1

Using the
static method
registerDriver(
) method
which is Either
available in forName() or
DriverManage registerDriver( None of the
r Class. ) given options 0 0 1
java.sql.Driver java.sql.Conn
java.sql.Driver Manager ection 1 0 0

Compiles but
Compilation error at run Compiles but
error time no output 0 0 1
ResultSetMet DatabaseMet Database.get
aData.getMax aData.getMax MaxConnectio
Connections Connections ns 0 0 1

false 1 0

Driver ResultSet Statement PreparedState


Interface Interface Interface ment Interface 1 0 0

Only B and C Both A and C


is True is TRUE All are TRUE 0 0 0
It returns int
value as
mentioned
below: > 0 if
many columns
Contain Null
Value < 0 if no
It returns true column
when last contains Null
read column Value = 0 if
contain SQL one column
NULL else contains Null none of the
returns false value listed options 0 1 0

java.sql.Driver
java.sql.Driver java.sql.DataS
java.sql.Driver Manager ource 0 0 1

executeAllSQ executeQuery executeUpdat


L() execute() () e() 0 0 1

executeQuery
executeSQL() execute() () 0 0 1

Compiles but
Compilation error at run
error will show city time 0 0 0

false 1 0
Read only, Updatable,
Updatable, Scroll Scroll
Forward only Sensitive sensitive 1 0 0
false 1 0

Only A is Only B is Both A and B


TRUE TRUE is TRUE 1 0 0

Both A and B Only A is Only B is


is TRUE TRUE TRUE 0 1 0

Compiles but Compiles but


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

CallableState PreparedState
ment ment RowSet 0 0 1

Line 13
creates a
Line 13 directory
An exception creates a File named “c” in
is thrown at object named the file
runtime “c” system. 0 0.5 0.5
1) Driver 2)
Connection 3)
ResultSet 4) 1) Driver 2)
ResultSetMet Connection 3)
aData 5) ResultSet 4)
Statement 6) ResultSetMet
DriverManage aData 5)
r 7) Statement 6)
PreparedState PreparedState
ment 8) ment 7)
Callablestate Callablestate
ment 9) ment 8)
DataBaseMet DataBaseMet All of the
aData aData given options 0 0 1

13 2 3 1 0 0

char [] int [6] Dog myDogs Dog myDogs


myChars; myScores; []; [7]; 0.333333 0.333333 0

Compiles but
error at run Compilation
282 time error 0 1 0
pkt = rat pkt = null rod = rat 0 1 0

A A
ParseExceptio NumberForma
n is thrown by tException is
the parse thrown by the
Compilation method at parse method
error runtime at runtime 0 1 0

Compilation
t9 a9 error 1 0 0
An exception
is thrown at
23 000 runtime 0 0 0

The program The program


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

The The
returnValue returnValue
can be any must be the
type, but will same type as
be the
automatically returnType, or
converted to If the be of a type
returnType returnType is that can be
when the void then the converted to
method returnValue returnType
returns to the can be any without loss of
caller. type information. 0 0 0
Compiles but
Compilation error at run
error time 0 1 0

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

Compiles but Compiles but


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

Compiles but
Compilation error at run
error time 1 0 0

Compilation
13.5 13 Error Runtime Error 0 0 0

sum = sum +
1; value = value = value value = value
value + sum; + sum; + ++sum; 1 0 0
19 follwed by Compile time 10 followed by
20 error 1 1 0 0

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


(D) (C) & (D) (A) & (B) 1 0 0

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

It can be
omitted, but if
not omitted
there are It can be
several The access omitted, but if
choices, modifier must not omitted it
including agree with the must be
private and type of the private or
public return value public 0 1 0

An exception
is thrown at
args[2] = 3 args[2] = null runtime 0 0 0
11, 1 10, 0 11 , 0 0 1 0

int [] myList = int myList [] [] int myList [] =


(5, 8, 2); = {4,9,7,0}; {4, 3, 7}; 0 0 0

disp X = 5 disp X = 5 Compilation


main X=5 main X=6 error 0 1 0

Three objects Four objects Two objects


and two and two and two
reference reference reference
variables variables variables. 1 0 0

Both A and B Both A and B


Only B is True is True is FALSE 1 0 0

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

2 3 4 0 0 1
Compiles but
Compilation error at run
error time 4 0 1 0

The variable The variable Compiles but


first is set to first is set to error at
null. elements[0]. runtime 0 0 1

compilation
0 6 1 7 2 8 3 9 0 5 1 5 2 5 3 5 fails 1 0 0

2 and 2 and 83886080 and


83886080 -83886080 2 0 0 0
Compilation
91 error 82 0 0 0

compile time runtime none of the


error at line 4 prints 34,56 exception listed options 0 1 0

An exception
Compilation is thrown at
9, 8, 7, 6, 5, fails runtime 0 0 1

B C D 0 0 0
Compiles but Compiles but
Compilation error at run run without
error time output 1 0 0

does not
var = 1 compile run time error 0 0 1

Simple
Association Dependency Composition 0 0 1

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

int [] a =
{23,22,21,20,1 int a [] = new
9}; int[5]; int [5] array; 0 1 0

int 1ah; int _; int $abc; 0 0 0.5


a: 10 b: 9 a: 9 b:9 a: 0 b:9 0 0 1

4 random value 1 0 0

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

value: 0 value: 1 value: 1


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

Compiles but Compiles but


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

A sequence of
Garbage
Values are compile time Compiles but
printed Error no output 0 0 1

construct(); start(); register(); 0 0 1


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

will print Hi Compilation will print Hi


Thrice error once 0 1 0

will print Hi
twice and
throws
will print Hi exception at
Once will not print runtime 0 0 0

will not create


compilation any child will display Hi
error thread once 1 0 0

wait() notify() run() terminate() 0.5 0 0


public class public class public class
MyRunnable MyRunnable MyRunnable
extends implements extends
Runnable{pub Runnable{void Object{public
lic void run(){}} run(){}} void run(){}} 1 0 0

Extend Implement
java.lang.Run Implement Implement java.lang.Thre
nable and java.lang.Thre java.lang.Run ad and
override the ad and nable and implement the
start() implement the implement the start()
method. run() method. run() method method. 0.5 0 0

Prints "Inside Throws


Does not Thread Inside exception at
compile Runnable" runtime 1 0 0

Only B and C Only A and B Only C and D


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

An exception It prints The output


occurs at "Thread one. cannot be
runtime. Thread two." determined. 0 1 0

Compiles but
throws run
compilation time a1 is not a
error Exception Thread 0 0 0

The code
The code executes
An exception executes normally, but
is thrown at normally and nothing is
runtime. prints "run". printed. 0 1 0
The code
executes
An exception normally and
is thrown at prints "Good prints Good
runtime. Day.." Day.. Twice 0 0 1

new
new new Thread(new
Thread(MyRu MyRunnable() MyRunnable()
nnable).run(); .start(); ).start(); 0 0 0

will not create


compilation any child will display Hi
error thread once 0 0 1

After the lock


on B is
released, or Two seconds Two seconds
after two after thread A after lock B is
seconds. is notified. released. 1 0 0
none of the
Thread class Interrupt class listed options 1 0 0

Compilation
hi world world error 0 0 0
Compilation
2 6 error 1 0 0

Compilation
1 4 fails. 0 0 0

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

true 1 0 1 0

result =
result.concat( concat(String
stringA, result+stringA A).concat(Stri
stringB, +stringB+strin ngB).concat(S
stringC ); gC; tringC) 1 0 0

Only B is Both A and B Both A and B


TRUE is TRUE is FALSE 0 0 1

One ring to One ring to


rule them all, rule them
One ring to all,\n One ring Different
find them. to find them. Starts 1 0 0
The program The program The program
will print The program will print will print
str3str1str2,w will print str3str1,when str3str2,when
hen run str3,when run run run 0 0 0

The second The second


The first line The first line line of output line of output
of output is of output is is abcd abc is abcd abcd
abc abc false abcd abc false false true 0 0 0.5

Cognizant Cognizant Technology


Technology Solutions Solutions 0 0 1

abc def ghi abc def + abc def +ghi 0 1 0


Complies but
Compilation exception at
anta error run time 1 0 0

A R I 0 0 1

iccratna ctna tna 0 0 1

abcabcDEFD abcdefabcDE none of the


EF F listed options 0 0 1

Compilation Compilation
and output the and output the Compile time
string "ello" string elloH error 0 0 0
Compilation
6 error 1 0 0

Compilation
at atm error 0 1 0

27 24 11 0 1 0

acitrcratna accircratna accrcratna 0 0 0

Only B is Both A and B Both A and B


TRUE is TRUE is FALSE 1 0 0

result =
result.concat( concat(String
stringA, result+stringA A).concat(Stri
stringB, +stringB+strin ngB).concat(S
stringC ); gC; tringC) 1 0 0
Compilation
hi world world error 1 0 0

Compilation
204 205 error 0 1 0

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

if(s.equals(s2) if(s.equalsIgn if(s.noCaseMa if(s.equalIgnor


) oreCase(s2)) tch(s2)) eCase(s2)) 0 0 1
s.defaultWrite s.writeObject(
s.serialize(x); Object(); x); 0 0 1

FileOutputStre
DataOutputStr am fos = new
FileOutputStre eam dos = FileOutputStre
am fos = new new am( new
FileOutputStre DataOutputStr BufferedOutp
am( "myData. eam( "myData utStream( "my
stuff") .stuff" ) Data.stuff") ) 0 1 0

A instance of
MyClass and
An exception An instance of an instance of
is thrown at MyClass is Tree are both
runtime serialized serialized 1 0 0
the state of
the object s1
Compiles but will not be
Compilation error at run store to the
error time file. 1 0 0

reads data
from file
named jlist.lst
in byte form Compiles but
Compilation and ascii error at
error value runtime 0 0 1

reads data
from file
named jlist.lst
in byte form Compiles but
Compilation and display error at
error garbage value runtime 1 0 0

Compiles and
Compiles but executes but
Compilation error at run directory is
error time not created 1 0 0
writes data to
the file in Compiles but
Compilation character error at
error form. runtime 1 0 0

Compilation
abcd ab cd abcd Error 0 0 0

the state of
the object s1
Compiles but will not be
Compilation error at run store to the
error time file. 0 0 1
reads data
from file
named jlist.lst
in byte form Compiles but
Compilation and display error at
error garbage value runtime 0 1 0

reads data
from file
named jlist.lst
in byte form Compiles but
Compilation and display error at
error garbage value runtime 1 0 0
throws a
throws a ArrayIndexOut
FileNotFound OfBoundsExc
Exception eption returns null 0 1 0

Compiles and
Compiles but executes but
Compilation error at run directories are
error time not created 0 0 0

I am a Person I am a
I am a I am a Student I am
Student Student a Person 0 1 0
B,C C,D A,B 0 0 0

writeFloat() write() writeDouble() 0 0 0

The file
The file system has a
The file system has a directory
system has a directory named
new empty named dir, newDir,
directory containing a containing a Compilation
named newDir file f1.txt file f1.txt error 0 0 0

Compiles and
runs but
Compiles but content not
Compilation error at transferred to
error runtime the temp.txt 0 0 0
The program
The program will compile,
The program will compile print H|e|l|l|o|,
will compile and print H|e|l| and then
and print H|e|l| l|o|End of terminate
l|o|Input error. stream. normally. 0 0 0

Compiles and Compiles but


Compilation runs without error at
error output runtime 1 0 0

The file is
modified from
The boolean The boolean being
value false is value true is unwritable to none of the
returned returned being writable. listed options 0 1 0
void add(int void add(int
char add(float x,int y) char x,int y) void
x) char add(char sum(double
add(float y) x,char y) x,double y) 0 0 1
avoiding
method name
Code flexibility confusion at
Code reuse at runtime runtime 0 0 1

Microprocess
or - Computer Tea -Cup Driver -Car 1 0 0

Segmentation Instantiation Composition 0 1 0

Behaviour Inheritance Identity 0 0 0


Grade4 Grade5

0.5

0
0

0
1

0
1

0
0

0
0

0
0

0
0

0
0

0 0.33

1
0

0
0

1
0

0
0

1
0

0
1

0
0

0.333333 0.333333

0 0.333333

0.333333 0

0 0
0

0
0

1 0

0
0

1
0

0
0

0 0
0

0 0

0
0

1
0

0
0

0 0

0
0

0
1

0 0
1

1 0

0.5 0

1
0

1
0

1
0

1 0

0
0

0 0

0
0.5

0
0 1

0
0

0
0

0 0
0

0
0

0
0

0.5 0

1 0
0

0
0 0.25

0 0.33
1

0
0

1
1 0

0.5 0
0

0
0

0.5

0.5

0
1

0.5

0
1 0

1 0
0

0
0 0

0
0.5 0.5

0
0

0
0

0 0.5

1
0

0
0

0.5 0

0
1

1 0

0 1
0

0
0

1
1

1
1

1
0

0
1

0
0.333333 0

0.5 0

0
0

1
0

1
0

0
0

0
0

0.333333

0
0

0 0.25

0
0 0

0
0

0 1
0

0
0 0

0
0 0

0.5 0.5

0 0

0.5 0

0
0

0 0

1
0

0 0

0
0

0
0

0.333333 0

0
0

0
1

1 0

1
0

0 1

1 0

0
0

1
0

0
0

1
1

0 0

1
0

0 0

0.5
0

0
0

0.5 0
0

0.5 0

0
0

0
0

1
0

0
1 0

0 0.5

0
0

1
0

0
0

0 0
0

0
0

0
0

0 1

0
0

0
1

1 0

1
1

0 0
0